-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
5 changed files
with
102 additions
and
18 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
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
"""Binary Sensor platform for the Adaptive Cover integration.""" | ||
|
||
from __future__ import annotations | ||
|
||
from homeassistant.components.binary_sensor import ( | ||
BinarySensorDeviceClass, | ||
BinarySensorEntity, | ||
) | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.device_registry import DeviceInfo | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
|
||
from .const import CONF_SENSOR_TYPE, DOMAIN | ||
from .coordinator import AdaptiveDataUpdateCoordinator | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Set up the Adaptive Cover binary sensor platform.""" | ||
coordinator: AdaptiveDataUpdateCoordinator = hass.data[DOMAIN][ | ||
config_entry.entry_id | ||
] | ||
|
||
binary_sensor = AdaptiveCoverBinarySensor( | ||
config_entry, | ||
config_entry.entry_id, | ||
"Sun Infront", | ||
False, | ||
BinarySensorDeviceClass.MOTION, | ||
coordinator, | ||
) | ||
async_add_entities([binary_sensor]) | ||
|
||
|
||
class AdaptiveCoverBinarySensor( | ||
CoordinatorEntity[AdaptiveDataUpdateCoordinator], BinarySensorEntity | ||
): | ||
"""representation of a Adaptive Cover binary sensor.""" | ||
|
||
_attr_has_entity_name = True | ||
_attr_should_poll = False | ||
_attr_translation_key = "sun_motion" | ||
|
||
def __init__( | ||
self, | ||
config_entry, | ||
unique_id: str, | ||
binary_name: str, | ||
state: bool, | ||
device_class: BinarySensorDeviceClass, | ||
coordinator: AdaptiveDataUpdateCoordinator, | ||
) -> None: | ||
"""Initialize the binary sensor.""" | ||
super().__init__(coordinator=coordinator) | ||
self.type = { | ||
"cover_blind": "Vertical", | ||
"cover_awning": "Horizontal", | ||
"cover_tilt": "Tilt", | ||
} | ||
self._name = config_entry.data["name"] | ||
self._device_name = self.type[config_entry.data[CONF_SENSOR_TYPE]] | ||
self._binary_name = binary_name | ||
self._attr_unique_id = unique_id | ||
self._state = state | ||
self._attr_device_class = device_class | ||
self._attr_device_info = DeviceInfo( | ||
identifiers={(DOMAIN, unique_id)}, | ||
name=self._device_name, | ||
) | ||
|
||
@property | ||
def name(self): | ||
"""Name of the entity.""" | ||
return f"{self._binary_name} {self._name}" | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
"""Return true if the binary sensor is on.""" | ||
return self.coordinator.data.states["binary"] |
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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"entity": { | ||
"binary_sensor": { | ||
"sun_motion": { | ||
"default": "mdi:weather-sunny", | ||
"state":{ | ||
"off": "mdi:weather-sunny-off" | ||
} | ||
} | ||
} | ||
} | ||
} |
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