123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import time # TODO remove
- import typing
- import homeassistant.const
- import homeassistant.core
- import homeassistant.helpers.entity
- class MCP3008Channel(homeassistant.helpers.entity.Entity):
- def __init__(self, channel_index: int) -> None:
- self._channel_index = channel_index
- self._state: typing.Optional[float] = None
- # https://developers.home-assistant.io/docs/core/entity/#generic-properties
- @property
- def name(self) -> str:
- return f"MCP3008 Channel #{self._channel_index}"
- @property
- def unique_id(self) -> str:
- return f"mcp3008-ch{self._channel_index}"
- # https://developers.home-assistant.io/docs/core/entity/sensor/#properties
- @property
- def state(self) -> typing.Optional[float]:
- return self._state
- @property
- def device_class(self) -> str:
- return "voltage"
- @property
- def unit_of_measurement(self) -> str:
- return homeassistant.const.VOLT
- def update(self) -> None:
- self._state = (time.time() / 60) % 60 # TODO
- def setup_platform(
- hass: homeassistant.core.HomeAssistant,
- config: dict,
- add_entities: typing.Callable,
- discovery_info=None,
- ):
- add_entities([MCP3008Channel(channel_index=0)])
|