Skip to content

Commit

Permalink
Merge pull request #230 from sockless-coding/eco-navi
Browse files Browse the repository at this point in the history
Added a switch for Eco navi
  • Loading branch information
sockless-coding authored Jun 28, 2024
2 parents e93c91d + c8bac49 commit b8588bc
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
17 changes: 17 additions & 0 deletions custom_components/panasonic_cc/panasonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions custom_components/panasonic_cc/pcomfortcloud/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
50 changes: 49 additions & 1 deletion custom_components/panasonic_cc/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand All @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit b8588bc

Please sign in to comment.