Skip to content

Commit

Permalink
Fixed issue with outside sensor showing 126
Browse files Browse the repository at this point in the history
Added option to force outside sensor being detected
  • Loading branch information
sockless-coding committed Aug 7, 2020
1 parent 2493b51 commit 3b0be9f
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 31 deletions.
8 changes: 6 additions & 2 deletions custom_components/panasonic_cc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
}
)
},
Expand Down Expand Up @@ -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:
Expand Down
40 changes: 37 additions & 3 deletions custom_components/panasonic_cc/config_flow.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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__)

Expand All @@ -24,14 +26,20 @@ 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
for entry in self._async_current_entries():
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."""
Expand Down Expand Up @@ -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])


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,
}
),
)
3 changes: 3 additions & 0 deletions custom_components/panasonic_cc/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

TIMEOUT = 60

CONF_FORCE_OUTSIDE_SENSOR = "force_outside_sensor"
DEFAULT_FORCE_OUTSIDE_SENSOR = False

SENSOR_TYPE_TEMPERATURE = "temperature"

SENSOR_TYPES = {
Expand Down
10 changes: 8 additions & 2 deletions custom_components/panasonic_cc/panasonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand Down
33 changes: 21 additions & 12 deletions custom_components/panasonic_cc/strings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}

33 changes: 21 additions & 12 deletions custom_components/panasonic_cc/translations/en.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}

0 comments on commit 3b0be9f

Please sign in to comment.