1 """Support for EZVIZ number controls."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
6 from datetime
import timedelta
9 from pyezviz.constants
import SupportExt
10 from pyezviz.exceptions
import (
11 EzvizAuthTokenExpired,
12 EzvizAuthVerificationCode,
25 from .const
import DATA_COORDINATOR, DOMAIN
26 from .coordinator
import EzvizDataUpdateCoordinator
27 from .entity
import EzvizBaseEntity
31 _LOGGER = logging.getLogger(__name__)
34 @dataclass(frozen=True, kw_only=True)
36 """Describe a EZVIZ Number."""
39 supported_ext_value: list
43 key=
"detection_sensibility",
44 translation_key=
"detection_sensibility",
45 entity_category=EntityCategory.CONFIG,
48 supported_ext=
str(SupportExt.SupportSensibilityAdjust.value),
49 supported_ext_value=[
"1",
"3"],
54 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
56 """Set up EZVIZ sensors based on a config entry."""
57 coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
62 EzvizNumber(coordinator, camera, value, entry.entry_id)
63 for camera
in coordinator.data
64 for capability, value
in coordinator.data[camera][
"supportExt"].items()
65 if capability == NUMBER_TYPE.supported_ext
66 if value
in NUMBER_TYPE.supported_ext_value
71 """Representation of a EZVIZ number entity."""
75 coordinator: EzvizDataUpdateCoordinator,
80 """Initialize the entity."""
81 super().
__init__(coordinator, serial)
90 """Run when about to be added to hass."""
95 """Return the state of the entity."""
101 """Set camera detection sensitivity."""
104 self.
coordinatorcoordinator.ezviz_client.detection_sensibility(
110 except (HTTPError, PyEzvizError)
as err:
112 f
"Cannot set detection sensitivity level on {self.name}"
118 """Fetch data from EZVIZ."""
119 _LOGGER.debug(
"Updating %s", self.
namename)
126 except (EzvizAuthTokenExpired, EzvizAuthVerificationCode):
127 _LOGGER.debug(
"Failed to login to EZVIZ API")
128 self.
hasshass.async_create_task(
133 except (InvalidURL, HTTPError, PyEzvizError)
as error:
None __init__(self, EzvizDataUpdateCoordinator coordinator, str serial, str value, str config_entry_id)
float|None native_value(self)
None async_added_to_hass(self)
None set_native_value(self, float value)
None async_schedule_update_ha_state(self, bool force_refresh=False)
str|UndefinedType|None name(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)