diff --git a/custom_components/panasonic_cc/__init__.py b/custom_components/panasonic_cc/__init__.py index 12e8058..b77010b 100644 --- a/custom_components/panasonic_cc/__init__.py +++ b/custom_components/panasonic_cc/__init__.py @@ -18,7 +18,7 @@ from homeassistant.helpers import discovery -from .const import TIMEOUT +from .const import TIMEOUT, CONF_FORCE_OUTSIDE_SENSOR, DEFAULT_FORCE_OUTSIDE_SENSOR from .panasonic import PanasonicApiDevice @@ -32,6 +32,7 @@ { vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string, + vol.Optional(CONF_FORCE_OUTSIDE_SENSOR, default=DEFAULT_FORCE_OUTSIDE_SENSOR): cv.boolean, } ) }, @@ -61,12 +62,15 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry): username = conf[CONF_USERNAME] password = conf[CONF_PASSWORD] + force_outside_sensor = False + if CONF_FORCE_OUTSIDE_SENSOR in conf: + force_outside_sensor = conf[CONF_FORCE_OUTSIDE_SENSOR] api = pcomfortcloud.Session(username, password, verifySsl=False) devices = await hass.async_add_executor_job(api.get_devices) for device in devices: try: - api_device = PanasonicApiDevice(hass, api, device) + api_device = PanasonicApiDevice(hass, api, device, force_outside_sensor) await api_device.update() hass.data[PANASONIC_DEVICES].append(api_device) except Exception as e: diff --git a/custom_components/panasonic_cc/config_flow.py b/custom_components/panasonic_cc/config_flow.py index 30f557c..534a239 100644 --- a/custom_components/panasonic_cc/config_flow.py +++ b/custom_components/panasonic_cc/config_flow.py @@ -1,5 +1,6 @@ """Config flow for the Panasonic Comfort Cloud platform.""" import asyncio +from typing import Any, Dict, Optional import logging from aiohttp import ClientError @@ -8,12 +9,13 @@ from homeassistant import config_entries from homeassistant.const import CONF_USERNAME, CONF_PASSWORD +from homeassistant.core import callback from . import DOMAIN as PANASONIC_DOMAIN from .panasonic import PanasonicApiDevice -from .const import KEY_DOMAIN, TIMEOUT +from .const import KEY_DOMAIN, TIMEOUT, CONF_FORCE_OUTSIDE_SENSOR _LOGGER = logging.getLogger(__name__) @@ -24,6 +26,12 @@ class FlowHandler(config_entries.ConfigFlow): VERSION = 1 CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL + @staticmethod + @callback + def async_get_options_flow(config_entry): + """Get the options flow for this handler.""" + return PanasonicOptionsFlowHandler(config_entry) + async def _create_entry(self, username, password): """Register new entry.""" # Check if ip already is registered @@ -31,7 +39,7 @@ async def _create_entry(self, username, password): if entry.data[KEY_DOMAIN] == PANASONIC_DOMAIN: return self.async_abort(reason="already_configured") - return self.async_create_entry(title="", data={CONF_USERNAME: username, CONF_PASSWORD: password}) + return self.async_create_entry(title="", data={CONF_USERNAME: username, CONF_PASSWORD: password, CONF_FORCE_OUTSIDE_SENSOR: False}) async def _create_device(self, username, password): """Create device.""" @@ -71,4 +79,30 @@ async def async_step_import(self, user_input): return await self.async_step_user() return await self._create_device(username, user_input[CONF_PASSWORD]) - \ No newline at end of file +class PanasonicOptionsFlowHandler(config_entries.OptionsFlow): + """Handle Panasonic options.""" + + def __init__(self, config_entry): + """Initialize Panasonic options flow.""" + self.config_entry = config_entry + + async def async_step_init( + self, user_input: Optional[Dict[str, Any]] = None + ) -> Dict[str, Any]: + """Manage Panasonic options.""" + if user_input is not None: + return self.async_create_entry(title="", data=user_input) + + return self.async_show_form( + step_id="init", + data_schema=vol.Schema( + { + vol.Optional( + CONF_FORCE_OUTSIDE_SENSOR, + default=self.config_entry.options.get( + CONF_FORCE_OUTSIDE_SENSOR, False + ), + ): bool, + } + ), + ) \ No newline at end of file diff --git a/custom_components/panasonic_cc/const.py b/custom_components/panasonic_cc/const.py index 4b9b666..fa9f2cd 100644 --- a/custom_components/panasonic_cc/const.py +++ b/custom_components/panasonic_cc/const.py @@ -18,6 +18,9 @@ TIMEOUT = 60 +CONF_FORCE_OUTSIDE_SENSOR = "force_outside_sensor" +DEFAULT_FORCE_OUTSIDE_SENSOR = False + SENSOR_TYPE_TEMPERATURE = "temperature" SENSOR_TYPES = { diff --git a/custom_components/panasonic_cc/panasonic.py b/custom_components/panasonic_cc/panasonic.py index 8d63b54..af27bf9 100644 --- a/custom_components/panasonic_cc/panasonic.py +++ b/custom_components/panasonic_cc/panasonic.py @@ -25,11 +25,12 @@ def wrapper_call(*args, **kwargs): class PanasonicApiDevice: - def __init__(self, hass: HomeAssistantType, api, device): + def __init__(self, hass: HomeAssistantType, api, device, force_outside_sensor): from pcomfortcloud import constants self.hass = hass self._api = api self.device = device + self.force_outside_sensor = force_outside_sensor self.id = device['id'] self.name = device['name'] self.group = device['group'] @@ -88,10 +89,15 @@ def support_inside_temperature(self): @property def outside_temperature(self): - return self.data['parameters']['temperatureOutside'] + temp = self.data['parameters']['temperatureOutside'] + if temp != 126: + return temp + return None @property def support_outside_temperature(self): + if self.force_outside_sensor: + return True return self.outside_temperature != 126 @property diff --git a/custom_components/panasonic_cc/strings.json b/custom_components/panasonic_cc/strings.json index 18440ef..fcc0884 100644 --- a/custom_components/panasonic_cc/strings.json +++ b/custom_components/panasonic_cc/strings.json @@ -1,17 +1,26 @@ { - "config": { - "step": { - "user": { - "title": "Panasonic Comfort Cloud", - "description": "Enter your Panasonic ID and password", - "data": { "username": "Panasonic ID", "password": "Password" } - } - }, - "abort": { - "device_timeout": "Timeout connecting to the device.", - "device_fail": "Unexpected error creating device.", - "already_configured": "Device is already configured" + "config": { + "step": { + "user": { + "title": "Panasonic Comfort Cloud", + "description": "Enter your Panasonic ID and password", + "data": { "username": "Panasonic ID", "password": "Password" } } + }, + "abort": { + "device_timeout": "Timeout connecting to the device.", + "device_fail": "Unexpected error creating device.", + "already_configured": "Device is already configured" + } + }, + "options": { + "step": { + "init": { + "data": { + "force_outside_sensor": "Force outside sensor" + } + } } } +} \ No newline at end of file diff --git a/custom_components/panasonic_cc/translations/en.json b/custom_components/panasonic_cc/translations/en.json index 18440ef..fcc0884 100644 --- a/custom_components/panasonic_cc/translations/en.json +++ b/custom_components/panasonic_cc/translations/en.json @@ -1,17 +1,26 @@ { - "config": { - "step": { - "user": { - "title": "Panasonic Comfort Cloud", - "description": "Enter your Panasonic ID and password", - "data": { "username": "Panasonic ID", "password": "Password" } - } - }, - "abort": { - "device_timeout": "Timeout connecting to the device.", - "device_fail": "Unexpected error creating device.", - "already_configured": "Device is already configured" + "config": { + "step": { + "user": { + "title": "Panasonic Comfort Cloud", + "description": "Enter your Panasonic ID and password", + "data": { "username": "Panasonic ID", "password": "Password" } } + }, + "abort": { + "device_timeout": "Timeout connecting to the device.", + "device_fail": "Unexpected error creating device.", + "already_configured": "Device is already configured" + } + }, + "options": { + "step": { + "init": { + "data": { + "force_outside_sensor": "Force outside sensor" + } + } } } +} \ No newline at end of file