Add service to set type of radar to retrieve. (#68252)
parent
280dcbed18
commit
caff81f613
|
@ -1,14 +1,24 @@
|
|||
"""Support for the Environment Canada radar imagery."""
|
||||
from __future__ import annotations
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.camera import Camera
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
AddEntitiesCallback,
|
||||
async_get_current_platform,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import ATTR_OBSERVATION_TIME, DOMAIN
|
||||
|
||||
SERVICE_SET_RADAR_TYPE = "set_radar_type"
|
||||
SET_RADAR_TYPE_SCHEMA = {
|
||||
vol.Required("radar_type"): vol.In(["Auto", "Rain", "Snow"]),
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
@ -19,6 +29,13 @@ async def async_setup_entry(
|
|||
coordinator = hass.data[DOMAIN][config_entry.entry_id]["radar_coordinator"]
|
||||
async_add_entities([ECCamera(coordinator)])
|
||||
|
||||
platform = async_get_current_platform()
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_RADAR_TYPE,
|
||||
SET_RADAR_TYPE_SCHEMA,
|
||||
"async_set_radar_type",
|
||||
)
|
||||
|
||||
|
||||
class ECCamera(CoordinatorEntity, Camera):
|
||||
"""Implementation of an Environment Canada radar camera."""
|
||||
|
@ -35,19 +52,17 @@ class ECCamera(CoordinatorEntity, Camera):
|
|||
self._attr_entity_registry_enabled_default = False
|
||||
|
||||
self.content_type = "image/gif"
|
||||
self.image = None
|
||||
self.observation_time = None
|
||||
|
||||
def camera_image(
|
||||
self, width: int | None = None, height: int | None = None
|
||||
) -> bytes | None:
|
||||
"""Return bytes of camera image."""
|
||||
if not hasattr(self.radar_object, "timestamp"):
|
||||
return None
|
||||
self.observation_time = self.radar_object.timestamp
|
||||
self._attr_extra_state_attributes = {
|
||||
ATTR_OBSERVATION_TIME: self.radar_object.timestamp,
|
||||
}
|
||||
return self.radar_object.image
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return the state attributes of the device."""
|
||||
return {ATTR_OBSERVATION_TIME: self.observation_time}
|
||||
async def async_set_radar_type(self, radar_type: str):
|
||||
"""Set the type of radar to retrieve."""
|
||||
self.radar_object.precip_type = radar_type.lower()
|
||||
await self.radar_object.update()
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
set_radar_type:
|
||||
name: Set radar type
|
||||
description: Set the type of radar image to retrieve.
|
||||
target:
|
||||
entity:
|
||||
integration: environment_canada
|
||||
domain: camera
|
||||
fields:
|
||||
radar_type:
|
||||
name: Radar type
|
||||
description: The type of radar image to display.
|
||||
required: true
|
||||
example: Snow
|
||||
selector:
|
||||
select:
|
||||
options:
|
||||
- "Auto"
|
||||
- "Rain"
|
||||
- "Snow"
|
Loading…
Reference in New Issue