-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
magnuselden
authored and
magnuselden
committed
Feb 22, 2023
1 parent
d8a7699
commit 2ebca37
Showing
12 changed files
with
156 additions
and
76 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 |
---|---|---|
@@ -1,45 +1,20 @@ | ||
import logging | ||
from datetime import timedelta | ||
|
||
from homeassistant.components.binary_sensor import BinarySensorEntity | ||
from homeassistant.core import HomeAssistant | ||
from peaqevcore.models.hub.const import CHARGERDONE | ||
|
||
from .const import ( | ||
import custom_components.peaqev.sensors.create_sensor_helper as helper | ||
from custom_components.peaqev.const import ( | ||
DOMAIN) | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entities): # pylint:disable=unused-argument | ||
hub = hass.data[DOMAIN]["hub"] | ||
|
||
peaqsensors = [] | ||
|
||
peaqsensors.append(PeaqBinarySensorDone(hub)) | ||
peaqsensors = helper.gather_binary_sensors(hub) | ||
async_add_entities(peaqsensors) | ||
|
||
SCAN_INTERVAL = timedelta(seconds=4) | ||
|
||
|
||
class PeaqBinarySensorDone(BinarySensorEntity): | ||
def __init__(self, hub) -> None: | ||
"""Initialize a Peaq Binary sensor.""" | ||
self._attr_name = f"{hub.hubname} {CHARGERDONE}" | ||
self._hub = hub | ||
self._attr_device_class = "none" | ||
|
||
@property | ||
def unique_id(self): | ||
return f"{DOMAIN.lower()}_{self._attr_name}" | ||
|
||
@property | ||
def device_info(self): | ||
return {"identifiers": {(DOMAIN, self._hub.hub_id)}} | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
try: | ||
return self._hub.sensors.charger_done.value | ||
except: | ||
_LOGGER.debug("Binarysensor_charger_done could not get state from hub.") | ||
return False |
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
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
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
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
Oops, something went wrong.