Demo: Remote improvements (#52265)
* Demo: Remote improvements * Address pylint warning
This commit is contained in:
parent
a7dd7c1a3d
commit
8a82557142
1 changed files with 32 additions and 32 deletions
|
@ -1,14 +1,32 @@
|
||||||
"""Demo platform that has two fake remotes."""
|
"""Demo platform that has two fake remotes."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Iterable
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.remote import RemoteEntity
|
from homeassistant.components.remote import RemoteEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import DEVICE_DEFAULT_NAME
|
from homeassistant.const import DEVICE_DEFAULT_NAME
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Set up the Demo config entry."""
|
"""Set up the Demo config entry."""
|
||||||
setup_platform(hass, {}, async_add_entities)
|
setup_platform(hass, {}, async_add_entities)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities_callback, discovery_info=None):
|
def setup_platform(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config: ConfigType,
|
||||||
|
add_entities_callback: AddEntitiesCallback,
|
||||||
|
discovery_info: dict[str, Any] | None = None,
|
||||||
|
) -> None:
|
||||||
"""Set up the demo remotes."""
|
"""Set up the demo remotes."""
|
||||||
add_entities_callback(
|
add_entities_callback(
|
||||||
[
|
[
|
||||||
|
@ -21,50 +39,32 @@ def setup_platform(hass, config, add_entities_callback, discovery_info=None):
|
||||||
class DemoRemote(RemoteEntity):
|
class DemoRemote(RemoteEntity):
|
||||||
"""Representation of a demo remote."""
|
"""Representation of a demo remote."""
|
||||||
|
|
||||||
def __init__(self, name, state, icon):
|
_attr_should_poll = False
|
||||||
|
|
||||||
|
def __init__(self, name: str | None, state: bool, icon: str | None) -> None:
|
||||||
"""Initialize the Demo Remote."""
|
"""Initialize the Demo Remote."""
|
||||||
self._name = name or DEVICE_DEFAULT_NAME
|
self._attr_name = name or DEVICE_DEFAULT_NAME
|
||||||
self._state = state
|
self._attr_is_on = state
|
||||||
self._icon = icon
|
self._attr_icon = icon
|
||||||
self._last_command_sent = None
|
self._last_command_sent = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def extra_state_attributes(self) -> dict[str, Any] | None:
|
||||||
"""No polling needed for a demo remote."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the device if any."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the icon to use for device if any."""
|
|
||||||
return self._icon
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self):
|
|
||||||
"""Return true if remote is on."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def extra_state_attributes(self):
|
|
||||||
"""Return device state attributes."""
|
"""Return device state attributes."""
|
||||||
if self._last_command_sent is not None:
|
if self._last_command_sent is not None:
|
||||||
return {"last_command_sent": self._last_command_sent}
|
return {"last_command_sent": self._last_command_sent}
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the remote on."""
|
"""Turn the remote on."""
|
||||||
self._state = True
|
self._attr_is_on = True
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the remote off."""
|
"""Turn the remote off."""
|
||||||
self._state = False
|
self._attr_is_on = False
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def send_command(self, command, **kwargs):
|
def send_command(self, command: Iterable[str], **kwargs: Any) -> None:
|
||||||
"""Send a command to a device."""
|
"""Send a command to a device."""
|
||||||
for com in command:
|
for com in command:
|
||||||
self._last_command_sent = com
|
self._last_command_sent = com
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue