Skip to content

Commit

Permalink
Merge pull request #16 from rospogrigio/droscy-improvements
Browse files Browse the repository at this point in the history
Some improvements
  • Loading branch information
rospogrigio authored Sep 23, 2021
2 parents c6add20 + dcdc9bf commit 521eb76
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*~
.tox
tools/daikin_data*.json
tools/tokenset.json

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
3 changes: 2 additions & 1 deletion custom_components/daikin_residential/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):

async def async_unload_entry(hass, config_entry):
"""Unload a config entry."""
_LOGGER.debug("Unloading integration...")
await asyncio.wait(
[
hass.config_entries.async_forward_entry_unload(config_entry, component)
for component in COMPONENT_TYPES
]
)
hass.data[DOMAIN].pop(config_entry.entry_id)
hass.data[DOMAIN].clear()
if not hass.data[DOMAIN]:
hass.data.pop(DOMAIN)
return True
Expand Down
11 changes: 11 additions & 0 deletions custom_components/daikin_residential/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ async def _set(self, settings):
if values:
await self._device.set(values)

@property
def available(self):
"""Return the availability of the underlying device."""
return self._device.available

@property
def supported_features(self):
"""Return the list of supported features."""
Expand Down Expand Up @@ -180,6 +185,12 @@ def target_temperature_step(self):

async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
# The service climate.set_temperature can set the hvac_mode too, see
# https://www.home-assistant.io/integrations/climate/#service-climateset_temperature
# se we first set the hvac_mode, if provided, then the temperature.
if ATTR_HVAC_MODE in kwargs:
await self.async_set_hvac_mode(kwargs[ATTR_HVAC_MODE])

await self._device.async_set_temperature(kwargs[ATTR_TEMPERATURE])

@property
Expand Down
7 changes: 5 additions & 2 deletions custom_components/daikin_residential/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, jsonData, apiInstance):
self.setJsonData(jsonData)
self.name = self.get_value("climateControl", "name")
# self.ip_address = device.device_ip
self._available = True

_LOGGER.info(
"Initialized Daikin Residential Device '%s' (id %s)",
self.name,
Expand All @@ -34,7 +34,10 @@ def __init__(self, jsonData, apiInstance):
@property
def available(self) -> bool:
"""Return True if entity is available."""
return self._available
try:
return self.desc["isCloudConnectionUp"]["value"]
except Exception:
return False

def device_info(self):
"""Return a device description for device registry."""
Expand Down
5 changes: 5 additions & 0 deletions custom_components/daikin_residential/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def __init__(self, device: Appliance, monitored_state: str, period="") -> None:
self._name = f"{device.name} {self._sensor[CONF_NAME]}"
self._device_attribute = monitored_state

@property
def available(self):
"""Return the availability of the underlying device."""
return self._device.available

@property
def unique_id(self):
"""Return a unique ID."""
Expand Down
5 changes: 5 additions & 0 deletions custom_components/daikin_residential/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def __init__(self, device: Appliance, switch_id: str):
self._switch_id = switch_id
self._name = f"{device.name} {switch_id}"

@property
def available(self):
"""Return the availability of the underlying device."""
return self._device.available

@property
def unique_id(self):
"""Return a unique ID."""
Expand Down

0 comments on commit 521eb76

Please sign in to comment.