Skip to content

Commit 3b0be9f

Browse files
Fixed issue with outside sensor showing 126
Added option to force outside sensor being detected
1 parent 2493b51 commit 3b0be9f

File tree

6 files changed

+96
-31
lines changed

6 files changed

+96
-31
lines changed

custom_components/panasonic_cc/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from homeassistant.helpers import discovery
2020

21-
from .const import TIMEOUT
21+
from .const import TIMEOUT, CONF_FORCE_OUTSIDE_SENSOR, DEFAULT_FORCE_OUTSIDE_SENSOR
2222

2323
from .panasonic import PanasonicApiDevice
2424

@@ -32,6 +32,7 @@
3232
{
3333
vol.Required(CONF_USERNAME): cv.string,
3434
vol.Required(CONF_PASSWORD): cv.string,
35+
vol.Optional(CONF_FORCE_OUTSIDE_SENSOR, default=DEFAULT_FORCE_OUTSIDE_SENSOR): cv.boolean,
3536
}
3637
)
3738
},
@@ -61,12 +62,15 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
6162

6263
username = conf[CONF_USERNAME]
6364
password = conf[CONF_PASSWORD]
65+
force_outside_sensor = False
66+
if CONF_FORCE_OUTSIDE_SENSOR in conf:
67+
force_outside_sensor = conf[CONF_FORCE_OUTSIDE_SENSOR]
6468

6569
api = pcomfortcloud.Session(username, password, verifySsl=False)
6670
devices = await hass.async_add_executor_job(api.get_devices)
6771
for device in devices:
6872
try:
69-
api_device = PanasonicApiDevice(hass, api, device)
73+
api_device = PanasonicApiDevice(hass, api, device, force_outside_sensor)
7074
await api_device.update()
7175
hass.data[PANASONIC_DEVICES].append(api_device)
7276
except Exception as e:

custom_components/panasonic_cc/config_flow.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Config flow for the Panasonic Comfort Cloud platform."""
22
import asyncio
3+
from typing import Any, Dict, Optional
34
import logging
45

56
from aiohttp import ClientError
@@ -8,12 +9,13 @@
89

910
from homeassistant import config_entries
1011
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
12+
from homeassistant.core import callback
1113

1214
from . import DOMAIN as PANASONIC_DOMAIN
1315

1416
from .panasonic import PanasonicApiDevice
1517

16-
from .const import KEY_DOMAIN, TIMEOUT
18+
from .const import KEY_DOMAIN, TIMEOUT, CONF_FORCE_OUTSIDE_SENSOR
1719

1820
_LOGGER = logging.getLogger(__name__)
1921

@@ -24,14 +26,20 @@ class FlowHandler(config_entries.ConfigFlow):
2426
VERSION = 1
2527
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL
2628

29+
@staticmethod
30+
@callback
31+
def async_get_options_flow(config_entry):
32+
"""Get the options flow for this handler."""
33+
return PanasonicOptionsFlowHandler(config_entry)
34+
2735
async def _create_entry(self, username, password):
2836
"""Register new entry."""
2937
# Check if ip already is registered
3038
for entry in self._async_current_entries():
3139
if entry.data[KEY_DOMAIN] == PANASONIC_DOMAIN:
3240
return self.async_abort(reason="already_configured")
3341

34-
return self.async_create_entry(title="", data={CONF_USERNAME: username, CONF_PASSWORD: password})
42+
return self.async_create_entry(title="", data={CONF_USERNAME: username, CONF_PASSWORD: password, CONF_FORCE_OUTSIDE_SENSOR: False})
3543

3644
async def _create_device(self, username, password):
3745
"""Create device."""
@@ -71,4 +79,30 @@ async def async_step_import(self, user_input):
7179
return await self.async_step_user()
7280
return await self._create_device(username, user_input[CONF_PASSWORD])
7381

74-
82+
class PanasonicOptionsFlowHandler(config_entries.OptionsFlow):
83+
"""Handle Panasonic options."""
84+
85+
def __init__(self, config_entry):
86+
"""Initialize Panasonic options flow."""
87+
self.config_entry = config_entry
88+
89+
async def async_step_init(
90+
self, user_input: Optional[Dict[str, Any]] = None
91+
) -> Dict[str, Any]:
92+
"""Manage Panasonic options."""
93+
if user_input is not None:
94+
return self.async_create_entry(title="", data=user_input)
95+
96+
return self.async_show_form(
97+
step_id="init",
98+
data_schema=vol.Schema(
99+
{
100+
vol.Optional(
101+
CONF_FORCE_OUTSIDE_SENSOR,
102+
default=self.config_entry.options.get(
103+
CONF_FORCE_OUTSIDE_SENSOR, False
104+
),
105+
): bool,
106+
}
107+
),
108+
)

custom_components/panasonic_cc/const.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
TIMEOUT = 60
2020

21+
CONF_FORCE_OUTSIDE_SENSOR = "force_outside_sensor"
22+
DEFAULT_FORCE_OUTSIDE_SENSOR = False
23+
2124
SENSOR_TYPE_TEMPERATURE = "temperature"
2225

2326
SENSOR_TYPES = {

custom_components/panasonic_cc/panasonic.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ def wrapper_call(*args, **kwargs):
2525

2626
class PanasonicApiDevice:
2727

28-
def __init__(self, hass: HomeAssistantType, api, device):
28+
def __init__(self, hass: HomeAssistantType, api, device, force_outside_sensor):
2929
from pcomfortcloud import constants
3030
self.hass = hass
3131
self._api = api
3232
self.device = device
33+
self.force_outside_sensor = force_outside_sensor
3334
self.id = device['id']
3435
self.name = device['name']
3536
self.group = device['group']
@@ -88,10 +89,15 @@ def support_inside_temperature(self):
8889

8990
@property
9091
def outside_temperature(self):
91-
return self.data['parameters']['temperatureOutside']
92+
temp = self.data['parameters']['temperatureOutside']
93+
if temp != 126:
94+
return temp
95+
return None
9296

9397
@property
9498
def support_outside_temperature(self):
99+
if self.force_outside_sensor:
100+
return True
95101
return self.outside_temperature != 126
96102

97103
@property
Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
{
2-
"config": {
3-
"step": {
4-
"user": {
5-
"title": "Panasonic Comfort Cloud",
6-
"description": "Enter your Panasonic ID and password",
7-
"data": { "username": "Panasonic ID", "password": "Password" }
8-
}
9-
},
10-
"abort": {
11-
"device_timeout": "Timeout connecting to the device.",
12-
"device_fail": "Unexpected error creating device.",
13-
"already_configured": "Device is already configured"
2+
"config": {
3+
"step": {
4+
"user": {
5+
"title": "Panasonic Comfort Cloud",
6+
"description": "Enter your Panasonic ID and password",
7+
"data": { "username": "Panasonic ID", "password": "Password" }
148
}
9+
},
10+
"abort": {
11+
"device_timeout": "Timeout connecting to the device.",
12+
"device_fail": "Unexpected error creating device.",
13+
"already_configured": "Device is already configured"
14+
}
15+
},
16+
"options": {
17+
"step": {
18+
"init": {
19+
"data": {
20+
"force_outside_sensor": "Force outside sensor"
21+
}
22+
}
1523
}
1624
}
25+
}
1726

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
{
2-
"config": {
3-
"step": {
4-
"user": {
5-
"title": "Panasonic Comfort Cloud",
6-
"description": "Enter your Panasonic ID and password",
7-
"data": { "username": "Panasonic ID", "password": "Password" }
8-
}
9-
},
10-
"abort": {
11-
"device_timeout": "Timeout connecting to the device.",
12-
"device_fail": "Unexpected error creating device.",
13-
"already_configured": "Device is already configured"
2+
"config": {
3+
"step": {
4+
"user": {
5+
"title": "Panasonic Comfort Cloud",
6+
"description": "Enter your Panasonic ID and password",
7+
"data": { "username": "Panasonic ID", "password": "Password" }
148
}
9+
},
10+
"abort": {
11+
"device_timeout": "Timeout connecting to the device.",
12+
"device_fail": "Unexpected error creating device.",
13+
"already_configured": "Device is already configured"
14+
}
15+
},
16+
"options": {
17+
"step": {
18+
"init": {
19+
"data": {
20+
"force_outside_sensor": "Force outside sensor"
21+
}
22+
}
1523
}
1624
}
25+
}
1726

0 commit comments

Comments
 (0)