-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5411738
commit 8d3e609
Showing
1 changed file
with
22 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,40 @@ | ||
from homeassistant.components.binary_sensor import BinarySensorEntity | ||
from typing import cast | ||
from homeassistant.components.binary_sensor import ( | ||
BinarySensorEntity, | ||
BinarySensorDeviceClass, | ||
) | ||
from homeassistant.const import CONF_DEVICE_ID, CONF_SENSORS, Platform | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from .const import DEVICES, DOMAIN | ||
from .midea_devices import MIDEA_DEVICES | ||
from .midea_entity import MideaEntity | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
|
||
async def async_setup_entry(hass, config_entry, async_add_entities): | ||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
device_id = config_entry.data.get(CONF_DEVICE_ID) | ||
device = hass.data[DOMAIN][DEVICES].get(device_id) | ||
extra_sensors = config_entry.options.get(CONF_SENSORS, []) | ||
binary_sensors = [] | ||
for entity_key, config in MIDEA_DEVICES[device.device_type]["entities"].items(): | ||
for entity_key, config in cast( | ||
dict, MIDEA_DEVICES[device.device_type]["entities"] | ||
).items(): | ||
if config["type"] == Platform.BINARY_SENSOR and entity_key in extra_sensors: | ||
sensor = MideaSensor(device, entity_key) | ||
sensor = MideaBinarySensor(device, entity_key) | ||
binary_sensors.append(sensor) | ||
async_add_entities(binary_sensors) | ||
|
||
|
||
class MideaSensor(MideaEntity, BinarySensorEntity): | ||
class MideaBinarySensor(MideaEntity, BinarySensorEntity): | ||
@property | ||
def device_class(self): | ||
return self._config.get("device_class") | ||
def device_class(self) -> BinarySensorDeviceClass | None: | ||
return cast(BinarySensorDeviceClass, self._config.get("device_class")) | ||
|
||
@property | ||
def is_on(self): | ||
return self._device.get_attribute(self._entity_key) | ||
def is_on(self) -> bool: | ||
return cast(bool, self._device.get_attribute(self._entity_key)) |