Skip to content

Commit

Permalink
Merge pull request #278 from sockless-coding/dev
Browse files Browse the repository at this point in the history
Added config option to force enable the Nanoe switch
  • Loading branch information
sockless-coding authored Aug 11, 2024
2 parents 6905df5 + 713ed95 commit 6801bda
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
15 changes: 14 additions & 1 deletion custom_components/panasonic_cc/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion custom_components/panasonic_cc/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
DEFAULT_ENERGY_FETCH_INTERVAL = 60
CONF_FORCE_ENABLE_NANOE = "force_enable_nanoe"
DEFAULT_FORCE_ENABLE_NANOE = False
2 changes: 2 additions & 0 deletions custom_components/panasonic_cc/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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)"
Expand Down
13 changes: 8 additions & 5 deletions custom_components/panasonic_cc/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
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
from .pcomfortcloud.changerequestbuilder import ChangeRequestBuilder


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

Expand Down Expand Up @@ -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:
Expand All @@ -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."""
Expand Down
2 changes: 2 additions & 0 deletions custom_components/panasonic_cc/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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)"
Expand Down

0 comments on commit 6801bda

Please sign in to comment.