New Huskey Water Timer Device
darrenblanchard opened this issue · comments
I think I may have it working:
Added to the _add_entity :
elif deviceClass == "water-timer":
_LOGGER.debug("Creating WaterTimer")
entities.append(HubspaceWaterTimer(hs, friendlyName, "1", debug))
entities.append(HubspaceWaterTimer(hs, friendlyName, "2", debug))
Added to the bottom of light.py :
class HubspaceWaterTimer(LightEntity):
"""Representation of an Awesome Light."""
def __init__(
self,
hs,
friendlyname,
outletIndex,
debug,
childId=None,
model=None,
deviceId=None,
deviceClass=None,
) -> None:
"""Initialize an AwesomeLight."""
self._name = friendlyname + "_spigot_" + outletIndex
self._debug = debug
self._state = "off"
self._childId = childId
self._model = model
self._brightness = None
self._usePrimaryFunctionInstance = False
self._hs = hs
self._deviceId = deviceId
self._debugInfo = None
self._outletIndex = outletIndex
if None in (childId, model, deviceId, deviceClass):
[
self._childId,
self._model,
self._deviceId,
deviceClass,
] = self._hs.getChildId(friendlyname)
async def async_setup_entry(hass, entry):
"""Set up the media player platform for Sonos."""
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
"send_command",
{
vol.Required("functionClass"): cv.string,
vol.Required("value"): cv.string,
vol.Optional("functionInstance"): cv.string,
},
"send_command",
)
@property
def name(self) -> str:
"""Return the display name of this light."""
return self._name
@property
def unique_id(self) -> str:
"""Return the display name of this light."""
return self._childId + "_" + self._outletIndex
@property
def color_mode(self) -> ColorMode:
"""Return the color mode of the light."""
return ColorMode.ONOFF
@property
def supported_color_modes(self) -> set[ColorMode]:
"""Flag supported color modes."""
return {self.color_mode}
def send_command(self, field_name, field_state, functionInstance=None) -> None:
self._hs.setState(self._childId, field_name, field_state, functionInstance)
def set_send_state(self, field_name, field_state) -> None:
self._hs.setState(self._childId, field_name, field_state)
@property
def is_on(self) -> bool | None:
"""Return true if light is on."""
if self._state is None:
return None
else:
return self._state == "on"
def turn_on(self, **kwargs: Any) -> None:
self._hs.setStateInstance(
self._childId, "toggle", "spigot-" + self._outletIndex, "on"
)
#self.update()
@property
def extra_state_attributes(self):
"""Return the state attributes."""
attr = {}
attr["model"] = self._model
attr["deviceId"] = self._deviceId + "_" + self._outletIndex
attr["devbranch"] = False
attr["debugInfo"] = self._debugInfo
return attr
def turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off."""
self._hs.setStateInstance(
self._childId, "toggle", "spigot-" + self._outletIndex, "off"
)
#self.update()
@property
def should_poll(self):
"""Turn on polling"""
return True
def update(self) -> None:
"""Fetch new state data for this light.
This is the only method that should fetch new data for Home Assistant.
"""
self._state = self._hs.getStateInstance(
self._childId, "toggle", "spigot-" + self._outletIndex
)
if self._debug:
self._debugInfo = self._hs.getDebugInfo(self._childId)
Yup. That is probably the best way to add it. Does it return a model number? Might be better to check that instead of deviceClass, just in case they release another water timer. But they may not return a model number, so what you did is ok in that case.
Make sure the code you added in _add_entity is before the:
else:
_LOGGER.debug("creating lights")
entities.append(HubspaceLight(hs, friendlyName, debug))
If you could do a PR to the latest code in the repo, that would be helpful. I just merged another PR, so add your code to the latest light.py
Nice job!
I have never done a Pull Request, I think I created one properly... Model number was "TBD"
I am having an issue where the water time doesn't auto load to which I add it in configuration and it kills the connection of my diskol fan. I tried adding the fan through configuration as well and it pulls it in through the main device name. While I don't mind having to rename or reset my automation, I wanted to know if there is not something else I should try before doing so. Thank you.
Autoload is only supported on a few devices, as I did not write that code. There is not a way to autoload for some devices, and use configuration file for others. Sorry.
You can look at light.py around line 239. That is how it autoloads a landscape transformer, which is close in structure to the water timer. You can add a block to try to autoload the water timer. I did not write the auto load code or the water timer code. And have no way to test. If you get it to work, please do a PR.
I was able to set up the timer using the water timer using the landscape transformer as a template. Still could bring in the plug that the setup came with to act as a WiFi hub. I am guessing that they use a different deviceId for it. How did you find out what the deviceId was for everything else?
I did put in a PR so things can get updated.