Skip to content

Commit

Permalink
Merge pull request #233 from sockless-coding/preset-1
Browse files Browse the repository at this point in the history
Panasonic Preset Naming
  • Loading branch information
sockless-coding authored Jun 29, 2024
2 parents ecb7b1c + efdd34d commit 9e1c053
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 35 deletions.
4 changes: 3 additions & 1 deletion custom_components/panasonic_cc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
DEFAULT_FORCE_OUTSIDE_SENSOR,
CONF_ENABLE_DAILY_ENERGY_SENSOR,
DEFAULT_ENABLE_DAILY_ENERGY_SENSOR,
CONF_USE_PANASONIC_PRESET_NAMES,
PANASONIC_DEVICES,
COMPONENT_TYPES)

Expand Down Expand Up @@ -67,6 +68,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
if CONF_FORCE_OUTSIDE_SENSOR in conf:
force_outside_sensor = conf[CONF_FORCE_OUTSIDE_SENSOR]
enable_daily_energy_sensor = entry.options.get(CONF_ENABLE_DAILY_ENERGY_SENSOR, DEFAULT_ENABLE_DAILY_ENERGY_SENSOR)
use_panasonic_preset_names = entry.options.get(CONF_USE_PANASONIC_PRESET_NAMES, False)

client = async_get_clientsession(hass)
api = pcomfortcloud.ApiClient(username, password, client)
Expand All @@ -76,7 +78,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

for device in devices:
try:
api_device = PanasonicApiDevice(hass, api, device, force_outside_sensor, enable_daily_energy_sensor)
api_device = PanasonicApiDevice(hass, api, device, force_outside_sensor, enable_daily_energy_sensor, use_panasonic_preset_names)
await api_device.update()
if enable_daily_energy_sensor:
await api_device.update_energy()
Expand Down
19 changes: 9 additions & 10 deletions custom_components/panasonic_cc/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ async def async_setup_entry(hass, entry, async_add_entities):
class PanasonicClimateDevice(ClimateEntity):

def __init__(self, api: PanasonicApiDevice):
"""Initialize the climate device."""
"""Initialize the climate device."""
self._api = api
self._attr_hvac_action = HVACAction.IDLE
self._enable_turn_on_off_backwards_compatibility = False
self._attr_translation_key = 'panasonic_climate'
self._attr_min_temp = api.min_temp
self._attr_max_temp = api.max_temp


@property
def unique_id(self):
Expand Down Expand Up @@ -127,6 +131,8 @@ async def async_set_hvac_mode(self, hvac_mode):
await self._api.turn_off()
else:
await self._api.set_hvac_mode(hvac_mode)
self._attr_min_temp = self._api.min_temp
self._attr_max_temp = self._api.max_temp

@property
def hvac_action(self):
Expand Down Expand Up @@ -213,6 +219,8 @@ def preset_mode(self) -> Optional[str]:
async def async_set_preset_mode(self, preset_mode):
"""Set preset mode."""
await self._api.set_preset_mode(preset_mode)
self._attr_min_temp = self._api.min_temp
self._attr_max_temp = self._api.max_temp

@property
def preset_modes(self) -> Optional[List[str]]:
Expand All @@ -222,15 +230,6 @@ def preset_modes(self) -> Optional[List[str]]:
#_LOGGER.debug("Preset modes are {0}".format(",".join(PRESET_LIST.keys())))
return self._api.available_presets

@property
def min_temp(self):
"""Return the minimum temperature."""
return self._api.min_temp

@property
def max_temp(self):
"""Return the maximum temperature."""
return self._api.max_temp

@property
def target_temp_step(self):
Expand Down
13 changes: 11 additions & 2 deletions custom_components/panasonic_cc/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
KEY_DOMAIN,
CONF_FORCE_OUTSIDE_SENSOR,
CONF_ENABLE_DAILY_ENERGY_SENSOR,
DEFAULT_ENABLE_DAILY_ENERGY_SENSOR)
DEFAULT_ENABLE_DAILY_ENERGY_SENSOR,
CONF_USE_PANASONIC_PRESET_NAMES,
DEFAULT_USE_PANASONIC_PRESET_NAMES)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -44,7 +46,8 @@ async def _create_entry(self, username, password):
CONF_USERNAME: username,
CONF_PASSWORD: password,
CONF_FORCE_OUTSIDE_SENSOR: False,
CONF_ENABLE_DAILY_ENERGY_SENSOR: DEFAULT_ENABLE_DAILY_ENERGY_SENSOR
CONF_ENABLE_DAILY_ENERGY_SENSOR: DEFAULT_ENABLE_DAILY_ENERGY_SENSOR,
CONF_USE_PANASONIC_PRESET_NAMES: DEFAULT_USE_PANASONIC_PRESET_NAMES
})

async def _create_device(self, username, password):
Expand Down Expand Up @@ -121,6 +124,12 @@ async def async_step_init(
CONF_ENABLE_DAILY_ENERGY_SENSOR, DEFAULT_ENABLE_DAILY_ENERGY_SENSOR
),
): bool,
vol.Optional(
CONF_USE_PANASONIC_PRESET_NAMES,
default=self.config_entry.options.get(
CONF_USE_PANASONIC_PRESET_NAMES, DEFAULT_USE_PANASONIC_PRESET_NAMES
),
): bool,
}
),
)
4 changes: 4 additions & 0 deletions custom_components/panasonic_cc/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
DEFAULT_FORCE_OUTSIDE_SENSOR = False
CONF_ENABLE_DAILY_ENERGY_SENSOR = "enable_daily_energy_sensor"
DEFAULT_ENABLE_DAILY_ENERGY_SENSOR = False
CONF_USE_PANASONIC_PRESET_NAMES = "use_panasonic_preset_names"
DEFAULT_USE_PANASONIC_PRESET_NAMES = True

SENSOR_TYPE_TEMPERATURE = "temperature"

PRESET_8_15 = "+8/15"
PRESET_QUIET = "quiet"
PRESET_POWERFUL = "powerful"

SENSOR_TYPES = {
ATTR_INSIDE_TEMPERATURE: {
Expand Down
18 changes: 18 additions & 0 deletions custom_components/panasonic_cc/icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"entity": {
"climate": {
"panasonic_climate":{
"state_attributes": {
"preset_mode": {
"state": {
"+8/15": "mdi:weather-sunny",
"quiet": "mdi:leaf",
"powerful": "mdi:arm-flex"
}
}
}
}
}
}
}

29 changes: 21 additions & 8 deletions custom_components/panasonic_cc/panasonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .pcomfortcloud.panasonicdevice import PanasonicDevice
from .pcomfortcloud import constants

from .const import PRESET_LIST, OPERATION_LIST, PRESET_8_15, PRESET_NONE, PRESET_ECO, PRESET_BOOST
from .const import OPERATION_LIST, PRESET_8_15, PRESET_NONE, PRESET_ECO, PRESET_BOOST, PRESET_QUIET, PRESET_POWERFUL

_LOGGER = logging.getLogger(__name__)

Expand All @@ -24,14 +24,22 @@

class PanasonicApiDevice:

def __init__(self, hass: HomeAssistant, api: ApiClient, device, force_outside_sensor, enable_energy_sensor): # noqa: E501
def __init__(
self,
hass: HomeAssistant,
api: ApiClient,
device,
force_outside_sensor,
enable_energy_sensor,
use_panasonic_preset_names: bool): # noqa: E501
from .pcomfortcloud import constants
self.hass = hass
self._api = api
self.device = device
self._details: PanasonicDevice = None
self.force_outside_sensor = force_outside_sensor
self.enable_energy_sensor = enable_energy_sensor
self._use_panasonic_preset_names = use_panasonic_preset_names
self.id = device['id']
self.name = device['name']
self.group = device['group']
Expand Down Expand Up @@ -289,13 +297,18 @@ async def turn_on(self):
)
await self.do_update()

def _get_quiet_preset(self):
return PRESET_QUIET if self._use_panasonic_preset_names else PRESET_ECO
def _get_powerful_preset(self):
return PRESET_POWERFUL if self._use_panasonic_preset_names else PRESET_BOOST

@cached_property
def available_presets(self):
presets = [PRESET_NONE]
if self._details.features.quiet_mode:
presets.append(PRESET_ECO)
presets.append(self._get_quiet_preset())
if self._details.features.powerful_mode:
presets.append(PRESET_BOOST)
presets.append(self._get_powerful_preset())
if self._details.features.summer_house > 0:
presets.append(PRESET_8_15)
return presets
Expand All @@ -306,9 +319,9 @@ def preset_mode(self):
return PRESET_NONE
match self._details.parameters.eco_mode:
case constants.EcoMode.Quiet:
return PRESET_ECO
return self._get_quiet_preset()
case constants.EcoMode.Powerful:
return PRESET_BOOST
return self._get_powerful_preset()
if self.in_summer_house_mode:
return PRESET_8_15

Expand Down Expand Up @@ -339,9 +352,9 @@ async def set_preset_mode(self, preset_mode: str) -> None:
if self.in_summer_house_mode and preset_mode != PRESET_8_15:
await self._exit_summer_house_mode(data)

if preset_mode == PRESET_ECO:
if preset_mode == self._get_quiet_preset():
data["eco"] = constants.EcoMode.Quiet
elif preset_mode == PRESET_BOOST:
elif preset_mode == self._get_powerful_preset():
data["eco"] = constants.EcoMode.Powerful
elif preset_mode == PRESET_8_15:
await self._enter_summer_house_mode()
Expand Down
32 changes: 25 additions & 7 deletions custom_components/panasonic_cc/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"user": {
"title": "Panasonic Comfort Cloud",
"description": "Enter your Panasonic ID and password",
"data": { "username": "Panasonic ID", "password": "Password" }
"data": {
"username": "Panasonic ID",
"password": "Password"
}
}
},
"abort": {
Expand All @@ -15,13 +18,28 @@
},
"options": {
"step": {
"init": {
"data": {
"force_outside_sensor": "Force outside sensor",
"enable_daily_energy_sensor": "Enable daily energy sensor (requires restart)"
"init": {
"data": {
"force_outside_sensor": "Force outside sensor",
"enable_daily_energy_sensor": "Enable daily energy sensor (requires restart)",
"use_panasonic_preset_names": "Use 'Quiet' and 'Powerful' instead of 'Eco' and 'Boost' Presets (requires restart)"
}
}
}
},
"entity": {
"climate": {
"panasonic_climate": {
"state_attributes": {
"preset_mode": {
"state": {
"+8/15": "+8/15°C",
"quiet": "Quiet",
"powerful": "Powerful"
}
}
}
}
}
}
}

}
32 changes: 25 additions & 7 deletions custom_components/panasonic_cc/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"user": {
"title": "Panasonic Comfort Cloud",
"description": "Enter your Panasonic ID and password",
"data": { "username": "Panasonic ID", "password": "Password" }
"data": {
"username": "Panasonic ID",
"password": "Password"
}
}
},
"abort": {
Expand All @@ -15,13 +18,28 @@
},
"options": {
"step": {
"init": {
"data": {
"force_outside_sensor": "Force outside sensor",
"enable_daily_energy_sensor": "Enable daily energy sensor (requires restart)"
"init": {
"data": {
"force_outside_sensor": "Force outside sensor",
"enable_daily_energy_sensor": "Enable daily energy sensor (requires restart)",
"use_panasonic_preset_names": "Use 'Quiet' and 'Powerful' instead of 'Eco' and 'Boost' Presets (requires restart)"
}
}
}
},
"entity": {
"climate": {
"panasonic_climate": {
"state_attributes": {
"preset_mode": {
"state": {
"+8/15": "+8/15°C",
"quiet": "Quiet",
"powerful": "Powerful"
}
}
}
}
}
}
}

}

0 comments on commit 9e1c053

Please sign in to comment.