Skip to content

Commit

Permalink
entity types
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Feb 12, 2023
1 parent 32d3d20 commit da2afb4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion custom_components/integration_blueprint/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ def __init__(
self.entity_description = entity_description

@property
def is_on(self):
def is_on(self) -> bool:
"""Return true if the binary_sensor is on."""
return self.coordinator.data.get("title", "") == "foo"
13 changes: 7 additions & 6 deletions custom_components/integration_blueprint/entity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""BlueprintEntity class"""
from __future__ import annotations

from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import ATTRIBUTION, DOMAIN, NAME, VERSION
Expand All @@ -16,9 +17,9 @@ def __init__(self, coordinator: BlueprintDataUpdateCoordinator) -> None:
"""Initialize."""
super().__init__(coordinator)
self._attr_unique_id = coordinator.config_entry.entry_id
self._attr_device_info = {
"identifiers": {(DOMAIN, self.unique_id)},
"name": NAME,
"model": VERSION,
"manufacturer": NAME,
}
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.unique_id)},
name=NAME,
model=VERSION,
manufacturer=NAME,
)
2 changes: 1 addition & 1 deletion custom_components/integration_blueprint/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ def __init__(
self.entity_description = entity_description

@property
def native_value(self):
def native_value(self) -> str:
"""Return the native value of the sensor."""
return self.coordinator.data.get("body")
6 changes: 3 additions & 3 deletions custom_components/integration_blueprint/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ def __init__(
self.entity_description = entity_description

@property
def is_on(self):
def is_on(self) -> bool:
"""Return true if the switch is on."""
return self.coordinator.data.get("title", "") == "foo"

async def async_turn_on(self, **kwargs: any): # pylint: disable=unused-argument
async def async_turn_on(self, **_: any) -> None:
"""Turn on the switch."""
await self.coordinator.api.async_set_title("bar")
await self.coordinator.async_request_refresh()

async def async_turn_off(self, **kwargs: any): # pylint: disable=unused-argument
async def async_turn_off(self, **_: any) -> None:
"""Turn off the switch."""
await self.coordinator.api.async_set_title("foo")
await self.coordinator.async_request_refresh()

0 comments on commit da2afb4

Please sign in to comment.