mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add service to set type of radar to retrieve. (#68252)
This commit is contained in:
parent
280dcbed18
commit
caff81f613
@ -1,14 +1,24 @@
|
|||||||
"""Support for the Environment Canada radar imagery."""
|
"""Support for the Environment Canada radar imagery."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.camera import Camera
|
from homeassistant.components.camera import Camera
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
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 homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import ATTR_OBSERVATION_TIME, DOMAIN
|
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(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -19,6 +29,13 @@ async def async_setup_entry(
|
|||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]["radar_coordinator"]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id]["radar_coordinator"]
|
||||||
async_add_entities([ECCamera(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):
|
class ECCamera(CoordinatorEntity, Camera):
|
||||||
"""Implementation of an Environment Canada radar camera."""
|
"""Implementation of an Environment Canada radar camera."""
|
||||||
@ -35,19 +52,17 @@ class ECCamera(CoordinatorEntity, Camera):
|
|||||||
self._attr_entity_registry_enabled_default = False
|
self._attr_entity_registry_enabled_default = False
|
||||||
|
|
||||||
self.content_type = "image/gif"
|
self.content_type = "image/gif"
|
||||||
self.image = None
|
|
||||||
self.observation_time = None
|
|
||||||
|
|
||||||
def camera_image(
|
def camera_image(
|
||||||
self, width: int | None = None, height: int | None = None
|
self, width: int | None = None, height: int | None = None
|
||||||
) -> bytes | None:
|
) -> bytes | None:
|
||||||
"""Return bytes of camera image."""
|
"""Return bytes of camera image."""
|
||||||
if not hasattr(self.radar_object, "timestamp"):
|
self._attr_extra_state_attributes = {
|
||||||
return None
|
ATTR_OBSERVATION_TIME: self.radar_object.timestamp,
|
||||||
self.observation_time = self.radar_object.timestamp
|
}
|
||||||
return self.radar_object.image
|
return self.radar_object.image
|
||||||
|
|
||||||
@property
|
async def async_set_radar_type(self, radar_type: str):
|
||||||
def extra_state_attributes(self):
|
"""Set the type of radar to retrieve."""
|
||||||
"""Return the state attributes of the device."""
|
self.radar_object.precip_type = radar_type.lower()
|
||||||
return {ATTR_OBSERVATION_TIME: self.observation_time}
|
await self.radar_object.update()
|
||||||
|
19
homeassistant/components/environment_canada/services.yaml
Normal file
19
homeassistant/components/environment_canada/services.yaml
Normal file
@ -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…
x
Reference in New Issue
Block a user