Skip to content

Commit

Permalink
Convert the Lock entity for the Child safeguard/operating lock switch (
Browse files Browse the repository at this point in the history
  • Loading branch information
ignisf authored Jan 25, 2023
1 parent f7a3b93 commit cc6707d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 19 deletions.
1 change: 1 addition & 0 deletions custom_components/dbuezas_eq3btsmart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
PLATFORMS = [
Platform.CLIMATE,
Platform.BUTTON,
Platform.LOCK,
Platform.SENSOR,
Platform.SWITCH,
Platform.BINARY_SENSOR,
Expand Down
61 changes: 61 additions & 0 deletions custom_components/dbuezas_eq3btsmart/lock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from .const import DOMAIN
import logging

from homeassistant.helpers.device_registry import format_mac
from .python_eq3bt.eq3bt.eq3btsmart import Mode, Thermostat
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
from homeassistant.components.lock import LockEntity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
eq3 = hass.data[DOMAIN][config_entry.entry_id]

new_devices = [
LockedSwitch(eq3),
]
async_add_entities(new_devices)


class Base(LockEntity):
def __init__(self, _thermostat: Thermostat):
self._thermostat = _thermostat
self._attr_has_entity_name = True

@property
def unique_id(self) -> str:
assert self.name
return format_mac(self._thermostat.mac) + "_" + self.name

@property
def device_info(self) -> DeviceInfo:
return DeviceInfo(
identifiers={(DOMAIN, self._thermostat.mac)},
)



class LockedSwitch(Base):
def __init__(self, _thermostat: Thermostat):
super().__init__(_thermostat)
_thermostat.register_update_callback(self.schedule_update_ha_state)
self._attr_name = "Locked"

async def async_lock(self):
await self._thermostat.async_set_locked(True)

async def async_unlock(self):
await self._thermostat.async_set_locked(False)

@property
def is_locked(self):
return self._thermostat.locked

19 changes: 0 additions & 19 deletions custom_components/dbuezas_eq3btsmart/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ async def async_setup_entry(
debug_mode = config_entry.options.get(CONF_DEBUG_MODE, False)

new_devices = [
LockedSwitch(eq3),
AwaySwitch(eq3),
BoostSwitch(eq3),
]
Expand All @@ -48,24 +47,6 @@ def device_info(self) -> DeviceInfo:
)


class LockedSwitch(Base):
def __init__(self, _thermostat: Thermostat):
super().__init__(_thermostat)
_thermostat.register_update_callback(self.schedule_update_ha_state)
self._attr_name = "Locked"
self._attr_icon = "mdi:lock"

async def async_turn_on(self):
await self._thermostat.async_set_locked(True)

async def async_turn_off(self):
await self._thermostat.async_set_locked(False)

@property
def is_on(self):
return self._thermostat.locked


class AwaySwitch(Base):
def __init__(self, _thermostat: Thermostat):
super().__init__(_thermostat)
Expand Down

0 comments on commit cc6707d

Please sign in to comment.