SonoffLAN icon indicating copy to clipboard operation
SonoffLAN copied to clipboard

climate entity for Sonoff TRVZB

Open bob-tm opened this issue 10 months ago • 6 comments

Added climate entity hvac mode now works like presets (off = off, heat = manual, auto = auto) fixed Child Lock and Window Switch

bob-tm avatar Jan 21 '25 21:01 bob-tm

Why did you create a custom BoolSwitch? What's the problem with the one that was?

AlexxIT avatar Jan 22 '25 07:01 AlexxIT

Why did you create a custom BoolSwitch? What's the problem with the one that was?

XBoolSwitch always toggle "switch" param. But childLock should use childLock param and windowSwitch should change windowSwitch.

Logic say it should be "switch" by default or self.param if self.param is set.

class XBoolSwitch(XEntity, SwitchEntity):
    params = {"switch"}

    def set_state(self, params: dict):
        self._attr_is_on = params["switch"]

    async def async_turn_on(self, *args, **kwargs):
        await self.ewelink.send(self.device, {"switch": True})

    async def async_turn_off(self):
        await self.ewelink.send(self.device, {"switch": False})
class XBoolSwitchTRVZB(XEntity, SwitchEntity):
    params = {}

    def set_state(self, params: dict):
        self._attr_is_on = params[self.param]

    async def async_turn_on(self, *args, **kwargs):
        await self.ewelink.send(self.device, {self.param: True})

    async def async_turn_off(self):
        await self.ewelink.send(self.device, {self.param: False})

bob-tm avatar Jan 22 '25 17:01 bob-tm

class XBinarySensor(XEntity, BinarySensorEntity):
    default_class: str = None

    def __init__(self, ewelink: XRegistry, device: dict):
        XEntity.__init__(self, ewelink, device)

        device_class = device.get("device_class", self.default_class)
        if device_class in DEVICE_CLASSES:
            self._attr_device_class = DEVICE_CLASSES[device_class]

    def set_state(self, params: dict):
        self._attr_is_on = params[self.param] == 1

There is another question.

workState and workMode can have values '0' or '1' - string type, not integer. Seems like XBinarySensor is better for them.

It is possible to change last line in XBinarySensor ?

self._attr_is_on = (params[self.param] == 1) or (params[self.param] == '1')

bob-tm avatar Jan 22 '25 18:01 bob-tm

depending on possibility of changing XBinarySensor code, I will push final TRVZB version with new XHexVoltageTRVZB class for runVoltage and BinarySensor for workMode

bob-tm avatar Jan 22 '25 19:01 bob-tm

I don't see the reason to have sensors for work state and work mode.

AlexxIT avatar Jan 23 '25 08:01 AlexxIT

I finish from my side. Everything works like expected. Please leave workstate sensor, to understand when head is changing the valve state.

bob-tm avatar Jan 26 '25 21:01 bob-tm

I've made some changes. I hope I didn't break anything. Writing a converter for such a device blindly is, of course, very difficult.

AlexxIT avatar Aug 14 '25 09:08 AlexxIT

https://github.com/AlexxIT/SonoffLAN/releases/tag/v3.9.0

AlexxIT avatar Aug 14 '25 15:08 AlexxIT