2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Volvo heater."""
|
2022-01-03 15:44:20 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-01-21 12:17:45 +00:00
|
|
|
from homeassistant.components.switch import SwitchEntity
|
2022-01-03 15:44:20 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2017-02-19 01:09:25 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import DATA_KEY, VolvoEntity
|
|
|
|
|
2017-02-19 01:09:25 +00:00
|
|
|
|
2022-01-03 15:44:20 +00:00
|
|
|
async def async_setup_platform(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
|
|
) -> None:
|
2018-10-05 05:48:40 +00:00
|
|
|
"""Set up a Volvo switch."""
|
2017-02-19 01:09:25 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
2018-11-30 18:07:42 +00:00
|
|
|
async_add_entities([VolvoSwitch(hass.data[DATA_KEY], *discovery_info)])
|
2017-02-19 01:09:25 +00:00
|
|
|
|
|
|
|
|
2022-01-21 12:17:45 +00:00
|
|
|
class VolvoSwitch(VolvoEntity, SwitchEntity):
|
2017-02-19 01:09:25 +00:00
|
|
|
"""Representation of a Volvo switch."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if switch is on."""
|
2018-11-30 18:07:42 +00:00
|
|
|
return self.instrument.state
|
2017-02-19 01:09:25 +00:00
|
|
|
|
2018-11-30 18:07:42 +00:00
|
|
|
async def async_turn_on(self, **kwargs):
|
2017-02-19 01:09:25 +00:00
|
|
|
"""Turn the switch on."""
|
2018-11-30 18:07:42 +00:00
|
|
|
await self.instrument.turn_on()
|
2020-04-22 08:10:59 +00:00
|
|
|
self.async_write_ha_state()
|
2017-02-19 01:09:25 +00:00
|
|
|
|
2018-11-30 18:07:42 +00:00
|
|
|
async def async_turn_off(self, **kwargs):
|
2017-02-19 01:09:25 +00:00
|
|
|
"""Turn the switch off."""
|
2018-11-30 18:07:42 +00:00
|
|
|
await self.instrument.turn_off()
|
2020-04-22 08:10:59 +00:00
|
|
|
self.async_write_ha_state()
|