diff --git a/custom_components/panasonic_cc/config_flow.py b/custom_components/panasonic_cc/config_flow.py index 18aa027..6a1145e 100644 --- a/custom_components/panasonic_cc/config_flow.py +++ b/custom_components/panasonic_cc/config_flow.py @@ -21,7 +21,9 @@ CONF_DEVICE_FETCH_INTERVAL, DEFAULT_DEVICE_FETCH_INTERVAL, CONF_ENERGY_FETCH_INTERVAL, - DEFAULT_ENERGY_FETCH_INTERVAL) + DEFAULT_ENERGY_FETCH_INTERVAL, + CONF_FORCE_ENABLE_NANOE, + DEFAULT_FORCE_ENABLE_NANOE) _LOGGER = logging.getLogger(__name__) @@ -50,6 +52,7 @@ async def _create_entry(self, username, password): CONF_USERNAME: username, CONF_PASSWORD: password, CONF_FORCE_OUTSIDE_SENSOR: False, + CONF_FORCE_ENABLE_NANOE: DEFAULT_FORCE_ENABLE_NANOE, CONF_ENABLE_DAILY_ENERGY_SENSOR: DEFAULT_ENABLE_DAILY_ENERGY_SENSOR, CONF_USE_PANASONIC_PRESET_NAMES: DEFAULT_USE_PANASONIC_PRESET_NAMES, CONF_DEVICE_FETCH_INTERVAL: DEFAULT_DEVICE_FETCH_INTERVAL, @@ -93,6 +96,10 @@ async def async_step_user(self, user_input=None): CONF_ENABLE_DAILY_ENERGY_SENSOR, default=DEFAULT_ENABLE_DAILY_ENERGY_SENSOR, ): bool, + vol.Optional( + CONF_FORCE_ENABLE_NANOE, + default=False, + ): bool, vol.Optional( CONF_USE_PANASONIC_PRESET_NAMES, default=DEFAULT_USE_PANASONIC_PRESET_NAMES, @@ -141,6 +148,12 @@ async def async_step_init( CONF_ENABLE_DAILY_ENERGY_SENSOR, DEFAULT_ENABLE_DAILY_ENERGY_SENSOR ), ): bool, + vol.Optional( + CONF_FORCE_ENABLE_NANOE, + default=self.config_entry.options.get( + CONF_FORCE_ENABLE_NANOE, DEFAULT_FORCE_ENABLE_NANOE + ), + ): bool, vol.Optional( CONF_USE_PANASONIC_PRESET_NAMES, default=self.config_entry.options.get( diff --git a/custom_components/panasonic_cc/const.py b/custom_components/panasonic_cc/const.py index b626da4..8287e78 100644 --- a/custom_components/panasonic_cc/const.py +++ b/custom_components/panasonic_cc/const.py @@ -118,4 +118,6 @@ CONF_DEVICE_FETCH_INTERVAL = "device_fetch_interval" CONF_ENERGY_FETCH_INTERVAL = "energy_fetch_interval" DEFAULT_DEVICE_FETCH_INTERVAL = 30 -DEFAULT_ENERGY_FETCH_INTERVAL = 60 \ No newline at end of file +DEFAULT_ENERGY_FETCH_INTERVAL = 60 +CONF_FORCE_ENABLE_NANOE = "force_enable_nanoe" +DEFAULT_FORCE_ENABLE_NANOE = False \ No newline at end of file diff --git a/custom_components/panasonic_cc/strings.json b/custom_components/panasonic_cc/strings.json index 9b25155..f300fec 100644 --- a/custom_components/panasonic_cc/strings.json +++ b/custom_components/panasonic_cc/strings.json @@ -8,6 +8,7 @@ "username": "Panasonic ID", "password": "Password", "enable_daily_energy_sensor": "Enable daily energy sensors", + "force_enable_nanoe": "Enable Nanoe switch for all devices", "use_panasonic_preset_names": "Use 'Quiet' and 'Powerful' instead of 'Eco' and 'Boost' Presets", "device_fetch_interval": "Device fetch interval (seconds)", "energy_fetch_interval": "Energy fetch interval (seconds)" @@ -26,6 +27,7 @@ "data": { "force_outside_sensor": "Force outside sensor", "enable_daily_energy_sensor": "Enable daily energy sensors (requires restart)", + "force_enable_nanoe": "Enable Nanoe switch for all devices (requires restart)", "use_panasonic_preset_names": "Use 'Quiet' and 'Powerful' instead of 'Eco' and 'Boost' Presets (requires restart)", "device_fetch_interval": "Device fetch interval (seconds)", "energy_fetch_interval": "Energy fetch interval (seconds)" diff --git a/custom_components/panasonic_cc/switch.py b/custom_components/panasonic_cc/switch.py index bc9d2c7..3d948d3 100644 --- a/custom_components/panasonic_cc/switch.py +++ b/custom_components/panasonic_cc/switch.py @@ -4,6 +4,7 @@ from dataclasses import dataclass from homeassistant.core import HomeAssistant +from homeassistant.config_entries import ConfigEntry from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity, SwitchEntityDescription from .pcomfortcloud import constants from .pcomfortcloud.panasonicdevice import PanasonicDevice, PanasonicDeviceZone @@ -11,7 +12,7 @@ from . import DOMAIN -from .const import DATA_COORDINATORS +from .const import DATA_COORDINATORS, CONF_FORCE_ENABLE_NANOE,DEFAULT_FORCE_ENABLE_NANOE from .coordinator import PanasonicDeviceCoordinator from .base import PanasonicDataEntity @@ -70,11 +71,12 @@ def create_zone_mode_description(zone: PanasonicDeviceZone): is_available=lambda device: True ) -async def async_setup_entry(hass: HomeAssistant, entry, async_add_entities): +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_entities): devices = [] data_coordinators: list[PanasonicDeviceCoordinator] = hass.data[DOMAIN][DATA_COORDINATORS] + force_enable_nanoe = entry.options.get(CONF_FORCE_ENABLE_NANOE, DEFAULT_FORCE_ENABLE_NANOE) for data_coordinator in data_coordinators: - devices.append(PanasonicSwitchEntity(data_coordinator, NANOE_DESCRIPTION)) + devices.append(PanasonicSwitchEntity(data_coordinator, NANOE_DESCRIPTION, always_available=force_enable_nanoe)) devices.append(PanasonicSwitchEntity(data_coordinator, ECONAVI_DESCRIPTION)) devices.append(PanasonicSwitchEntity(data_coordinator, ECO_FUNCTION_DESCRIPTION)) if data_coordinator.device.has_zones: @@ -94,15 +96,16 @@ class PanasonicSwitchEntityBase(SwitchEntity): class PanasonicSwitchEntity(PanasonicDataEntity, PanasonicSwitchEntityBase): """Representation of a Panasonic switch.""" - def __init__(self, coordinator: PanasonicDeviceCoordinator, description: PanasonicSwitchEntityDescription): + def __init__(self, coordinator: PanasonicDeviceCoordinator, description: PanasonicSwitchEntityDescription, always_available: bool = False): """Initialize the Switch.""" self.entity_description = description + self._always_available = always_available super().__init__(coordinator, description.key) @property def available(self) -> bool: """Return if entity is available.""" - return self.entity_description.is_available(self.coordinator.device) + return self._always_available or self.entity_description.is_available(self.coordinator.device) def _async_update_attrs(self) -> None: """Update the attributes of the sensor.""" diff --git a/custom_components/panasonic_cc/translations/en.json b/custom_components/panasonic_cc/translations/en.json index 83935b0..b1788d3 100644 --- a/custom_components/panasonic_cc/translations/en.json +++ b/custom_components/panasonic_cc/translations/en.json @@ -8,6 +8,7 @@ "username": "Panasonic ID", "password": "Password", "enable_daily_energy_sensor": "Enable daily energy sensors", + "force_enable_nanoe": "Enable Nanoe switch for all devices", "use_panasonic_preset_names": "Use 'Quiet' and 'Powerful' instead of 'Eco' and 'Boost' Presets", "device_fetch_interval": "Device fetch interval (seconds)", "energy_fetch_interval": "Energy fetch interval (seconds)" @@ -26,6 +27,7 @@ "data": { "force_outside_sensor": "Force outside sensor", "enable_daily_energy_sensor": "Enable daily energy sensors (requires restart)", + "force_enable_nanoe": "Enable Nanoe switch for all devices (requires restart)", "use_panasonic_preset_names": "Use 'Quiet' and 'Powerful' instead of 'Eco' and 'Boost' Presets (requires restart)", "device_fetch_interval": "Device fetch interval (seconds)", "energy_fetch_interval": "Energy fetch interval (seconds)"