Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions homeassistant/components/daikin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
# For backwards compat, set unique ID
if entry.unique_id is None:
hass.config_entries.async_update_entry(entry, unique_id=conf[KEY_MAC])
daikin_api = await daikin_api_setup(
hass,
conf[CONF_HOST],
conf.get(CONF_KEY),
conf.get(CONF_UUID),
conf.get(CONF_PASSWORD),
)
daikin_api = await daikin_api_setup(hass, entry)
if not daikin_api:
return False
hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: daikin_api})
Expand All @@ -102,36 +96,39 @@ async def async_unload_entry(hass, config_entry):
return True


async def daikin_api_setup(hass, host, key, uuid, password):
async def daikin_api_setup(hass, entry):
"""Create a Daikin instance only once."""

session = hass.helpers.aiohttp_client.async_get_clientsession()
try:
with timeout(TIMEOUT):
device = await Appliance.factory(
host, session, key=key, uuid=uuid, password=password
device_id=entry.data[CONF_HOST],
session=hass.helpers.aiohttp_client.async_get_clientsession(),
key=entry.data.get(CONF_KEY),
uuid=entry.data.get(CONF_UUID),
password=entry.data.get(CONF_PASSWORD),
)
except asyncio.TimeoutError:
_LOGGER.debug("Connection to %s timed out", host)
_LOGGER.debug("Connection to %s timed out", entry.data[CONF_HOST])
raise ConfigEntryNotReady
except ClientConnectionError:
_LOGGER.debug("ClientConnectionError to %s", host)
_LOGGER.debug("ClientConnectionError to %s", entry.data[CONF_HOST])
raise ConfigEntryNotReady
except Exception: # pylint: disable=broad-except
_LOGGER.error("Unexpected error creating device %s", host)
_LOGGER.error("Unexpected error creating device %s", entry.data[CONF_HOST])
return None

api = DaikinApi(device)
api = DaikinApi(device, entry)

return api


class DaikinApi:
"""Keep the Daikin instance in one place and centralize the update."""

def __init__(self, device: Appliance):
def __init__(self, device: Appliance, entry: ConfigEntry):
"""Initialize the Daikin Handle."""
self.device = device
self.entry = entry
self.name = device.values.get("name", "Daikin AC")
self.ip_address = device.device_ip
self._available = True
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/daikin/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
ATTR_STATE_OFF,
ATTR_STATE_ON,
ATTR_TARGET_TEMPERATURE,
CONF_TEMPERATURE_STEPS,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -130,7 +131,9 @@ async def _set(self, settings):
# temperature
elif attr == ATTR_TEMPERATURE:
try:
values[HA_ATTR_TO_DAIKIN[ATTR_TARGET_TEMPERATURE]] = str(int(value))
values[HA_ATTR_TO_DAIKIN[ATTR_TARGET_TEMPERATURE]] = str(
float(value)
)
except ValueError:
_LOGGER.error("Invalid temperature %s", value)

Expand Down Expand Up @@ -170,6 +173,8 @@ def target_temperature(self):
@property
def target_temperature_step(self):
"""Return the supported step of target temperature."""
if self._api.entry.options.get(CONF_TEMPERATURE_STEPS):
return 0.5
return 1

async def async_set_temperature(self, **kwargs):
Expand Down
46 changes: 44 additions & 2 deletions homeassistant/components/daikin/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@

from homeassistant import config_entries
from homeassistant.const import CONF_HOST, CONF_PASSWORD

from .const import CONF_KEY, CONF_UUID, KEY_HOSTNAME, KEY_IP, KEY_MAC, TIMEOUT
from homeassistant.core import callback

from .const import (
CONF_KEY,
CONF_TEMPERATURE_STEPS,
CONF_UUID,
KEY_HOSTNAME,
KEY_IP,
KEY_MAC,
TIMEOUT,
)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -132,3 +141,36 @@ async def async_step_zeroconf(self, discovery_info):
self._abort_if_unique_id_configured()
self.host = discovery_info[CONF_HOST]
return await self.async_step_user()

@staticmethod
@callback
def async_get_options_flow(config_entry):
"""Get the options flow for this handler."""
return DaikinOptionsFlowHandler(config_entry)


class DaikinOptionsFlowHandler(config_entries.OptionsFlow):
"""Handle Daikin client options."""

def __init__(self, config_entry):
"""Initialize Daikin options flow."""
self.config_entry = config_entry

async def async_step_init(self, user_input=None):
"""Manage the Daikin 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.Required(
CONF_TEMPERATURE_STEPS,
default=self.config_entry.options.get(
CONF_TEMPERATURE_STEPS, False
),
): bool
}
),
)
2 changes: 2 additions & 0 deletions homeassistant/components/daikin/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
CONF_KEY = "key"
CONF_UUID = "uuid"

CONF_TEMPERATURE_STEPS = "temperature_steps"

KEY_MAC = "mac"
KEY_IP = "ip"
KEY_HOSTNAME = "hostname"
Expand Down
10 changes: 10 additions & 0 deletions homeassistant/components/daikin/strings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"options": {
"step": {
"init": {
"title": "Configure options for Daikin",
"data": {
"temperature_steps": "Use 0.5 steps for target temperature (default is 1.0)."
}
}
}
},
"config": {
"step": {
"user": {
Expand Down