-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add socket support * Revert removal version file
- Loading branch information
Showing
18 changed files
with
331 additions
and
11 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
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 |
---|---|---|
|
@@ -72,6 +72,11 @@ | |
"alarm_water": { | ||
"name": "Water Alarm" | ||
} | ||
}, | ||
"switch": { | ||
"socket": { | ||
"name": "Socket" | ||
} | ||
} | ||
} | ||
} |
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,119 @@ | ||
"""The Elro Connects switch platform.""" | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
import logging | ||
|
||
from elro.command import SOCKET_OFF, SOCKET_ON, CommandAttributes | ||
from elro.device import ( | ||
ATTR_DEVICE_STATE, | ||
ATTR_DEVICE_VALUE, | ||
DEVICE_VALUE_OFF, | ||
DEVICE_VALUE_ON, | ||
SOCKET, | ||
STATES_OFFLINE, | ||
) | ||
|
||
from homeassistant.components.switch import ( | ||
SwitchDeviceClass, | ||
SwitchEntity, | ||
SwitchEntityDescription, | ||
) | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from .device import ElroConnectsEntity, ElroConnectsK1 | ||
from .helpers import async_set_up_discovery_helper | ||
|
||
|
||
@dataclass | ||
class ElroSwitchEntityDescription(SwitchEntityDescription): | ||
"""A class that describes elro siren entities.""" | ||
|
||
turn_on: CommandAttributes | None = None | ||
turn_off: CommandAttributes | None = None | ||
|
||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
SWITCH_DEVICE_TYPES = { | ||
SOCKET: ElroSwitchEntityDescription( | ||
key=SOCKET, | ||
translation_key="socket", | ||
device_class=SwitchDeviceClass.OUTLET, | ||
turn_on=SOCKET_ON, | ||
turn_off=SOCKET_OFF, | ||
), | ||
} | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Set up the sensor platform.""" | ||
current: set[int] = set() | ||
|
||
async_set_up_discovery_helper( | ||
hass, | ||
ElroConnectsSwitch, | ||
config_entry, | ||
current, | ||
SWITCH_DEVICE_TYPES, | ||
async_add_entities, | ||
) | ||
|
||
|
||
class ElroConnectsSwitch(ElroConnectsEntity, SwitchEntity): | ||
"""Elro Connects Fire Alarm Entity.""" | ||
|
||
def __init__( | ||
self, | ||
elro_connects_api: ElroConnectsK1, | ||
entry: ConfigEntry, | ||
device_id: int, | ||
description: ElroSwitchEntityDescription, | ||
) -> None: | ||
"""Initialize a Fire Alarm Entity.""" | ||
self._attr_has_entity_name = True | ||
self._device_id = device_id | ||
self._elro_connects_api = elro_connects_api | ||
self._description = description | ||
ElroConnectsEntity.__init__( | ||
self, | ||
elro_connects_api, | ||
entry, | ||
device_id, | ||
description, | ||
) | ||
|
||
@property | ||
def is_on(self) -> bool | None: | ||
"""Return true if device is on or none if the device is offline.""" | ||
if not self.data or self.data[ATTR_DEVICE_STATE] in STATES_OFFLINE: | ||
return None | ||
if self.data[ATTR_DEVICE_VALUE] not in (DEVICE_VALUE_OFF, DEVICE_VALUE_ON): | ||
return None | ||
return self.data[ATTR_DEVICE_VALUE] == DEVICE_VALUE_ON | ||
|
||
async def async_turn_on(self, **kwargs) -> None: | ||
"""Turn switch on.""" | ||
_LOGGER.debug("Sending turn_on request for entity %s", self.entity_id) | ||
await self._elro_connects_api.async_command( | ||
self._description.turn_on, device_ID=self._device_id | ||
) | ||
|
||
self.data[ATTR_DEVICE_VALUE] = DEVICE_VALUE_ON | ||
self.async_write_ha_state() | ||
|
||
async def async_turn_off(self, **kwargs) -> None: | ||
"""Turn switch off.""" | ||
_LOGGER.debug("Sending turn_off request for entity %s", self.entity_id) | ||
await self._elro_connects_api.async_command( | ||
self._description.turn_off, device_ID=self._device_id | ||
) | ||
|
||
self.data[ATTR_DEVICE_VALUE] = DEVICE_VALUE_OFF | ||
self.async_write_ha_state() |
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 |
---|---|---|
|
@@ -72,6 +72,11 @@ | |
"alarm_water": { | ||
"name": "Wasseralarm" | ||
} | ||
}, | ||
"switch": { | ||
"socket": { | ||
"name": "Wandsteckdose" | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -72,6 +72,11 @@ | |
"alarm_water": { | ||
"name": "Water Alarm" | ||
} | ||
}, | ||
"switch": { | ||
"socket": { | ||
"name": "Socket" | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -72,6 +72,11 @@ | |
"alarm_water": { | ||
"name": "Alarma de agua" | ||
} | ||
}, | ||
"switch": { | ||
"socket": { | ||
"name": "Toma de pared" | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -72,6 +72,11 @@ | |
"alarm_water": { | ||
"name": "Alarme d'eau" | ||
} | ||
}, | ||
"switch": { | ||
"socket": { | ||
"name": "La prise électrique" | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -72,6 +72,11 @@ | |
"alarm_water": { | ||
"name": "Wateralarm" | ||
} | ||
}, | ||
"switch": { | ||
"socket": { | ||
"name": "Stopcontact" | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -72,6 +72,11 @@ | |
"alarm_water": { | ||
"name": "Alarme de água" | ||
} | ||
}, | ||
"switch": { | ||
"socket": { | ||
"name": "Tomada de parede" | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -72,6 +72,11 @@ | |
"alarm_water": { | ||
"name": "Сигналізація води" | ||
} | ||
}, | ||
"switch": { | ||
"socket": { | ||
"name": "Розетка" | ||
} | ||
} | ||
} | ||
} |
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,4 +1,4 @@ | ||
pre-commit==3.3.1 | ||
lib-elro-connects==0.5.4.1 | ||
lib-elro-connects==0.6.0.1 | ||
homeassistant==2023.7.2 | ||
pytest-homeassistant-custom-component==0.13.44 |
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 |
---|---|---|
|
@@ -6,12 +6,12 @@ | |
requirements = [ | ||
"sqlalchemy", | ||
] | ||
with open("requirements_test.txt") as f: | ||
with open("requirements_test.txt", encoding="utf-8") as f: | ||
for line in f: | ||
if "txt" not in line and "#" not in line: | ||
requirements.append(line) | ||
|
||
with open("version") as f: | ||
with open("version", encoding="utf-8") as f: | ||
__version__ = f.read() | ||
|
||
setup( | ||
|
@@ -26,13 +26,12 @@ | |
author_email="[email protected]", | ||
description="Add Elro Connects alarm devices to Home Assistant", | ||
classifiers=[ | ||
"Development Status :: 3 - Alpha", | ||
"Development Status :: 4 - Beta", | ||
"Framework :: Pytest", | ||
"Intended Audience :: Developers", | ||
"Intended Audience :: Information Technology", | ||
"License :: OSI Approved :: MIT License", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3.9", | ||
"Topic :: Software Development :: Testing", | ||
], | ||
entry_points={ | ||
"pytest11": ["homeassistant = pytest_homeassistant_custom_component.plugins"] | ||
|
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.