Kevin Worrel fb48fd7d10
ScreenLogic cleanups (#48136)
* ScreenLogic cleanup.
Bump screenlogicpy to 0.2.0.
Move heating functions from water_heater to climate platform.
Address notes from original PR.

* Fix temperature attribute

* Addressing notes.
Bump screenlogicpy to 0.2.1.
Made device_types constants.
Made (known) equipment flags constants.
Used dict.get() in places where None is the default.
Return fast with good _last_preset.

* Update homeassistant/components/screenlogic/climate.py

Let base entity handle state property.

Co-authored-by: J. Nick Koston <nick@koston.org>

* Patch integration setup functions.

* Exception, ATTR_TEMPERATURE notes

Co-authored-by: J. Nick Koston <nick@koston.org>
2021-03-21 11:56:46 +01:00

61 lines
1.8 KiB
Python

"""Support for a ScreenLogic 'circuit' switch."""
import logging
from screenlogicpy.const import ON_OFF
from homeassistant.components.switch import SwitchEntity
from . import ScreenlogicEntity
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up entry."""
entities = []
data = hass.data[DOMAIN][config_entry.entry_id]
coordinator = data["coordinator"]
for switch in data["devices"]["switch"]:
entities.append(ScreenLogicSwitch(coordinator, switch))
async_add_entities(entities)
class ScreenLogicSwitch(ScreenlogicEntity, SwitchEntity):
"""ScreenLogic switch entity."""
@property
def name(self):
"""Get the name of the switch."""
return f"{self.gateway_name} {self.circuit['name']}"
@property
def is_on(self) -> bool:
"""Get whether the switch is in on state."""
return self.circuit["value"] == 1
async def async_turn_on(self, **kwargs) -> None:
"""Send the ON command."""
return await self._async_set_circuit(ON_OFF.ON)
async def async_turn_off(self, **kwargs) -> None:
"""Send the OFF command."""
return await self._async_set_circuit(ON_OFF.OFF)
async def _async_set_circuit(self, circuit_value) -> None:
if await self.hass.async_add_executor_job(
self.gateway.set_circuit, self._data_key, circuit_value
):
_LOGGER.debug("Turn %s %s", self._data_key, circuit_value)
await self.coordinator.async_request_refresh()
else:
_LOGGER.warning(
"Failed to set_circuit %s %s", self._data_key, circuit_value
)
@property
def circuit(self):
"""Shortcut to access the circuit."""
return self.coordinator.data["circuits"][self._data_key]