diff --git a/custom_components/panasonic_cc/panasonic.py b/custom_components/panasonic_cc/panasonic.py index 2c90b7c..b40afda 100644 --- a/custom_components/panasonic_cc/panasonic.py +++ b/custom_components/panasonic_cc/panasonic.py @@ -261,6 +261,14 @@ def max_temp(self): return 15 if self._details.features.summer_house == 2 else 10 return 30 + @cached_property + def support_eco_navi(self) -> bool: + return self._details.features.eco_navi + + @property + def eco_navi(self): + return self._details.parameters.eco_navi_mode + async def turn_off(self): await self.set_device( { "power": self.constants.Power.Off } @@ -450,6 +458,15 @@ async def set_nanoe_mode(self, nanoe_mode): ) await self.do_update() + async def set_eco_navi_mode(self, eco_navi: constants.EcoNaviMode): + """Set new nanoe mode.""" + _LOGGER.debug("Set %s eco navi mode %s", self.name, eco_navi.name) + + await self.set_device( + { "nanoe": eco_navi } + ) + await self.do_update() + async def set_device(self, args): try: diff --git a/custom_components/panasonic_cc/pcomfortcloud/constants.py b/custom_components/panasonic_cc/pcomfortcloud/constants.py index 4ca8a68..1d277d4 100644 --- a/custom_components/panasonic_cc/pcomfortcloud/constants.py +++ b/custom_components/panasonic_cc/pcomfortcloud/constants.py @@ -69,6 +69,10 @@ class NanoeMode(Enum): ModeG = 3 All = 4 +class EcoNaviMode(Enum): + Off = 0 + On = 1 + INVALID_TEMPERATURE = 126 DEFAULT_X_APP_VERSION = "1.21.0" diff --git a/custom_components/panasonic_cc/pcomfortcloud/panasonicdevice.py b/custom_components/panasonic_cc/pcomfortcloud/panasonicdevice.py index 374bf4b..97de99c 100644 --- a/custom_components/panasonic_cc/pcomfortcloud/panasonicdevice.py +++ b/custom_components/panasonic_cc/pcomfortcloud/panasonicdevice.py @@ -78,6 +78,7 @@ def __init__(self, json = None) -> None: self.vertical_swing_mode = constants.AirSwingUD.Mid self.eco_mode = constants.EcoMode.Auto self.nanoe_mode = constants.NanoeMode.Unavailable + self.eco_navi_mode = constants.EcoNaviMode.Off self.target_temperature: int = None self.inside_temperature: int = None self.outside_temperature: int = None @@ -101,6 +102,8 @@ def load(self, json): self.eco_mode = constants.EcoMode(json['ecoMode']) if 'nanoe' in json: self.nanoe_mode = constants.NanoeMode(json['nanoe']) + if 'ecoNavi' in json: + self.eco_navi_mode = constants.NanoeMode(json['ecoNavi']) def _load_temperature(self, json): if 'temperatureSet' in json and json['temperatureSet'] != constants.INVALID_TEMPERATURE: diff --git a/custom_components/panasonic_cc/switch.py b/custom_components/panasonic_cc/switch.py index 9c45ffc..7038719 100644 --- a/custom_components/panasonic_cc/switch.py +++ b/custom_components/panasonic_cc/switch.py @@ -2,6 +2,8 @@ import logging from homeassistant.helpers.entity import ToggleEntity +from .panasonic import PanasonicApiDevice +from .pcomfortcloud import constants from . import DOMAIN as PANASONIC_DOMAIN, PANASONIC_DEVICES @@ -12,6 +14,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None): devices = [] for device in hass.data[PANASONIC_DEVICES]: devices.append(PanasonicNanoeSwitch(device)) + if device.support_eco_navi: + devices.append(PanasonicEcoNaviSwitch(device)) add_entities(devices) async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): @@ -26,7 +30,7 @@ async def async_setup_entry(hass, entry, async_add_entities): class PanasonicNanoeSwitch(ToggleEntity): """Representation of a zone.""" - def __init__(self, api_device): + def __init__(self, api_device:PanasonicApiDevice): """Initialize the zone.""" self._api = api_device @@ -66,3 +70,47 @@ async def async_turn_on(self, **kwargs): async def async_turn_off(self, **kwargs): """Turn off nanoe.""" await self._api.set_nanoe_mode(self._api.constants.NanoeMode.Off.name) + +class PanasonicEcoNaviSwitch(ToggleEntity): + """Representation of a zone.""" + + def __init__(self, api_device:PanasonicApiDevice): + """Initialize the zone.""" + self._api = api_device + + @property + def unique_id(self): + """Return a unique ID.""" + return f"{self._api.id}-eco-navi" + + @property + def icon(self): + """Icon to use in the frontend, if any.""" + return "mdi:leaf" + + @property + def name(self): + """Return the name of the sensor.""" + return f"{self._api.name} Eco Navi" + + @property + def is_on(self): + """Return the state of the sensor.""" + return self._api.nanoe_mode == constants.EcoNaviMode.On + + @property + def device_info(self): + """Return a device description for device registry.""" + return self._api.device_info + + async def async_update(self): + """Retrieve latest state.""" + await self._api.update() + + async def async_turn_on(self, **kwargs): + """Turn on nanoe.""" + await self._api.set_eco_navi_mode(constants.EcoNaviMode.On) + + async def async_turn_off(self, **kwargs): + """Turn off nanoe.""" + await self._api.set_eco_navi_mode(constants.EcoNaviMode.Off)