From 03f6045d34ab53c17b56fe2c5cb1849501b61be6 Mon Sep 17 00:00:00 2001 From: Jean-Marc Collin Date: Fri, 15 Dec 2023 22:58:36 +0000 Subject: [PATCH] Ignore central confic in instanciate entities --- .../versatile_thermostat/binary_sensor.py | 64 ++++++++++++++----- .../versatile_thermostat/climate.py | 5 ++ .../versatile_thermostat/sensor.py | 5 ++ 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/custom_components/versatile_thermostat/binary_sensor.py b/custom_components/versatile_thermostat/binary_sensor.py index 19c2e7b..3e5cc0a 100644 --- a/custom_components/versatile_thermostat/binary_sensor.py +++ b/custom_components/versatile_thermostat/binary_sensor.py @@ -20,6 +20,8 @@ from .const import ( CONF_USE_PRESENCE_FEATURE, CONF_USE_MOTION_FEATURE, CONF_USE_WINDOW_FEATURE, + CONF_THERMOSTAT_TYPE, + CONF_THERMOSTAT_CENTRAL_CONFIG, ) _LOGGER = logging.getLogger(__name__) @@ -37,8 +39,15 @@ async def async_setup_entry( unique_id = entry.entry_id name = entry.data.get(CONF_NAME) + vt_type = entry.data.get(CONF_THERMOSTAT_TYPE) - entities = [SecurityBinarySensor(hass, unique_id, name, entry.data),WindowByPassBinarySensor(hass, unique_id, name, entry.data)] + if vt_type == CONF_THERMOSTAT_CENTRAL_CONFIG: + return + + entities = [ + SecurityBinarySensor(hass, unique_id, name, entry.data), + WindowByPassBinarySensor(hass, unique_id, name, entry.data), + ] if entry.data.get(CONF_USE_MOTION_FEATURE): entities.append(MotionBinarySensor(hass, unique_id, name, entry.data)) if entry.data.get(CONF_USE_WINDOW_FEATURE): @@ -55,8 +64,12 @@ class SecurityBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity): """Representation of a BinarySensor which exposes the security state""" def __init__( - self, hass: HomeAssistant, unique_id, name, entry_infos - ) -> None: # pylint: disable=unused-argument + self, + hass: HomeAssistant, + unique_id, + name, # pylint: disable=unused-argument + entry_infos, + ) -> None: """Initialize the SecurityState Binary sensor""" super().__init__(hass, unique_id, entry_infos.get(CONF_NAME)) self._attr_name = "Security state" @@ -90,8 +103,12 @@ class OverpoweringBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity """Representation of a BinarySensor which exposes the overpowering state""" def __init__( - self, hass: HomeAssistant, unique_id, name, entry_infos - ) -> None: # pylint: disable=unused-argument + self, + hass: HomeAssistant, + unique_id, + name, # pylint: disable=unused-argument + entry_infos, + ) -> None: """Initialize the OverpoweringState Binary sensor""" super().__init__(hass, unique_id, entry_infos.get(CONF_NAME)) self._attr_name = "Overpowering state" @@ -125,8 +142,12 @@ class WindowBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity): """Representation of a BinarySensor which exposes the window state""" def __init__( - self, hass: HomeAssistant, unique_id, name, entry_infos - ) -> None: # pylint: disable=unused-argument + self, + hass: HomeAssistant, + unique_id, + name, # pylint: disable=unused-argument + entry_infos, + ) -> None: """Initialize the WindowState Binary sensor""" super().__init__(hass, unique_id, entry_infos.get(CONF_NAME)) self._attr_name = "Window state" @@ -171,8 +192,12 @@ class MotionBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity): """Representation of a BinarySensor which exposes the motion state""" def __init__( - self, hass: HomeAssistant, unique_id, name, entry_infos - ) -> None: # pylint: disable=unused-argument + self, + hass: HomeAssistant, + unique_id, + name, # pylint: disable=unused-argument + entry_infos, + ) -> None: """Initialize the MotionState Binary sensor""" super().__init__(hass, unique_id, entry_infos.get(CONF_NAME)) self._attr_name = "Motion state" @@ -207,8 +232,12 @@ class PresenceBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity): """Representation of a BinarySensor which exposes the presence state""" def __init__( - self, hass: HomeAssistant, unique_id, name, entry_infos - ) -> None: # pylint: disable=unused-argument + self, + hass: HomeAssistant, + unique_id, + name, # pylint: disable=unused-argument + entry_infos, + ) -> None: """Initialize the PresenceState Binary sensor""" super().__init__(hass, unique_id, entry_infos.get(CONF_NAME)) self._attr_name = "Presence state" @@ -239,13 +268,18 @@ class PresenceBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity): else: return "mdi:nature-people" -#PR - Adding Window ByPass + +# PR - Adding Window ByPass class WindowByPassBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity): """Representation of a BinarySensor which exposes the Window ByPass state""" def __init__( - self, hass: HomeAssistant, unique_id, name, entry_infos - ) -> None: # pylint: disable=unused-argument + self, + hass: HomeAssistant, + unique_id, + name, # pylint: disable=unused-argument + entry_infos, + ) -> None: """Initialize the WindowByPass Binary sensor""" super().__init__(hass, unique_id, entry_infos.get(CONF_NAME)) self._attr_name = "Window bypass" @@ -272,4 +306,4 @@ class WindowByPassBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity if self._attr_is_on: return "mdi:window-shutter-cog" else: - return "mdi:window-shutter-auto" \ No newline at end of file + return "mdi:window-shutter-auto" diff --git a/custom_components/versatile_thermostat/climate.py b/custom_components/versatile_thermostat/climate.py index 6ccd558..7e2f9e6 100644 --- a/custom_components/versatile_thermostat/climate.py +++ b/custom_components/versatile_thermostat/climate.py @@ -37,6 +37,7 @@ from .const import ( CONF_THERMOSTAT_SWITCH, CONF_THERMOSTAT_CLIMATE, CONF_THERMOSTAT_VALVE, + CONF_THERMOSTAT_CENTRAL_CONFIG, ) from .thermostat_switch import ThermostatOverSwitch @@ -64,7 +65,11 @@ async def async_setup_entry( name = entry.data.get(CONF_NAME) vt_type = entry.data.get(CONF_THERMOSTAT_TYPE) + if vt_type == CONF_THERMOSTAT_CENTRAL_CONFIG: + return + # Instantiate the right base class + entity = None if vt_type == CONF_THERMOSTAT_SWITCH: entity = ThermostatOverSwitch(hass, unique_id, name, entry.data) elif vt_type == CONF_THERMOSTAT_CLIMATE: diff --git a/custom_components/versatile_thermostat/sensor.py b/custom_components/versatile_thermostat/sensor.py index a72833d..4c8bf05 100644 --- a/custom_components/versatile_thermostat/sensor.py +++ b/custom_components/versatile_thermostat/sensor.py @@ -27,6 +27,7 @@ from .const import ( CONF_THERMOSTAT_VALVE, CONF_THERMOSTAT_CLIMATE, CONF_THERMOSTAT_TYPE, + CONF_THERMOSTAT_CENTRAL_CONFIG, ) THRESHOLD_WATT_KILO = 100 @@ -46,6 +47,10 @@ async def async_setup_entry( unique_id = entry.entry_id name = entry.data.get(CONF_NAME) + vt_type = entry.data.get(CONF_THERMOSTAT_TYPE) + + if vt_type == CONF_THERMOSTAT_CENTRAL_CONFIG: + return entities = [ LastTemperatureSensor(hass, unique_id, name, entry.data),