-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
e72e5c1
commit e099848
Showing
2 changed files
with
69 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
import asyncio | ||
import voluptuous as vol | ||
|
||
from functools import cached_property, partial | ||
|
||
from homeassistant.components.template.sensor import SensorTemplate | ||
from homeassistant.components.template.sensor import TriggerSensorEntity | ||
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription | ||
from homeassistant.helpers.template import Template | ||
|
||
from homeassistant.core import HomeAssistant, callback | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import EntityCategory, STATE_OFF, STATE_ON | ||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo, format_mac | ||
from homeassistant.helpers.entity import Entity, ToggleEntity | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
from homeassistant.components.binary_sensor import BinarySensorEntity, BinarySensorDeviceClass | ||
|
||
from .const import * | ||
from .common import * | ||
from .services import * | ||
from .entity import SolarmanEntity | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
_PLATFORM = get_current_file_name(__name__) | ||
|
||
def _create_sensor(coordinator, sensor): | ||
try: | ||
entity = SolarmanBinarySensorEntity(coordinator, sensor) | ||
|
||
entity.update() | ||
|
||
return entity | ||
except BaseException as e: | ||
_LOGGER.error(f"Configuring {sensor} failed. [{format_exception(e)}]") | ||
raise | ||
|
||
async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: | ||
_LOGGER.debug(f"async_setup_entry: {config.options}") | ||
coordinator = hass.data[DOMAIN][config.entry_id] | ||
|
||
sensors = coordinator.inverter.get_sensors() | ||
|
||
# Add entities. | ||
# | ||
_LOGGER.debug(f"async_setup: async_add_entities") | ||
|
||
async_add_entities(_create_sensor(coordinator, sensor) for sensor in sensors if ("class" in sensor and sensor["class"] == _PLATFORM)) | ||
|
||
return True | ||
|
||
async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: | ||
_LOGGER.debug(f"async_unload_entry: {config.options}") | ||
|
||
return True | ||
|
||
class SolarmanBinarySensorEntity(SolarmanEntity, BinarySensorEntity): | ||
def __init__(self, coordinator, sensor): | ||
SolarmanEntity.__init__(self, coordinator, _PLATFORM, sensor) | ||
|
||
@property | ||
def is_on(self) -> bool | None: | ||
return self._attr_state != 0 |
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