-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thermopro: add set_datetime service for TP358/TP393
- Loading branch information
Showing
6 changed files
with
116 additions
and
4 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,98 @@ | ||
"""Demo platform that offers a fake button entity.""" | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from thermopro_ble import ThermoProDevice | ||
|
||
from homeassistant.components import persistent_notification | ||
from homeassistant.components.bluetooth import async_ble_device_from_address | ||
from homeassistant.components.button import ButtonEntity | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import device_registry as dr | ||
from homeassistant.helpers.device_registry import DeviceInfo | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
from homeassistant.util.dt import now | ||
|
||
from . import DOMAIN | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Set up the demo button platform.""" | ||
|
||
assert config_entry.unique_id is not None | ||
|
||
device_registry = dr.async_get(hass) | ||
device = device_registry.async_get_device( | ||
connections={(dr.CONNECTION_BLUETOOTH, config_entry.unique_id)}, | ||
identifiers={(dr.CONNECTION_BLUETOOTH, config_entry.unique_id)}, | ||
) | ||
|
||
assert device is not None | ||
|
||
_LOGGER.debug("UHUHUHUH %s - %s - %s", config_entry, config_entry.data, device) | ||
|
||
if device.model not in ("TP358", "TP393"): | ||
return | ||
|
||
async_add_entities( | ||
[ | ||
ThermoProButton( | ||
address=config_entry.unique_id, | ||
unique_id="push", | ||
device_name="Push", | ||
), | ||
] | ||
) | ||
|
||
|
||
class ThermoProButton(ButtonEntity): | ||
"""Representation of a demo button entity.""" | ||
|
||
_attr_has_entity_name = True | ||
_attr_name = None | ||
_attr_should_poll = False | ||
|
||
def __init__( | ||
self, | ||
address: str, | ||
unique_id: str, | ||
device_name: str, | ||
) -> None: | ||
"""Initialize the Demo button entity.""" | ||
self.address = address | ||
self._attr_unique_id = unique_id | ||
self._attr_device_info = DeviceInfo( | ||
identifiers={(DOMAIN, unique_id)}, | ||
name=device_name, | ||
) | ||
|
||
async def async_press(self) -> None: | ||
"""Send out a persistent notification.""" | ||
address = self.address | ||
|
||
assert address is not None | ||
|
||
dt = now() | ||
|
||
persistent_notification.async_create( | ||
self.hass, f"Button pressed {address} {dt}", title="Button" | ||
) | ||
|
||
ble = async_ble_device_from_address(self.hass, address, connectable=True) | ||
|
||
assert ble is not None | ||
|
||
tpd = ThermoProDevice(ble) | ||
|
||
await tpd.set_datetime(dt, False) | ||
|
||
self.hass.bus.async_fire("demo_button_pressed") |
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,7 @@ | ||
{ | ||
"services": { | ||
"set_datetime": { | ||
"service": "mdi:clock" | ||
} | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.