1 """UptimeRobot switch platform."""
3 from __future__
import annotations
7 from pyuptimerobot
import UptimeRobotAuthenticationException, UptimeRobotException
12 SwitchEntityDescription,
18 from .const
import API_ATTR_OK, DOMAIN, LOGGER
19 from .coordinator
import UptimeRobotDataUpdateCoordinator
20 from .entity
import UptimeRobotEntity
24 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
26 """Set up the UptimeRobot switches."""
27 coordinator: UptimeRobotDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
33 device_class=SwitchDeviceClass.SWITCH,
37 for monitor
in coordinator.data
42 """Representation of a UptimeRobot switch."""
44 _attr_translation_key =
"monitor_status"
48 """Return True if the entity is on."""
52 """Edit monitor status."""
54 response = await self.
apiapi.async_edit_monitor(**kwargs)
55 except UptimeRobotAuthenticationException:
56 LOGGER.debug(
"API authentication error, calling reauth")
57 self.coordinator.config_entry.async_start_reauth(self.
hasshass)
59 except UptimeRobotException
as exception:
60 LOGGER.error(
"API exception: %s", exception)
63 if response.status != API_ATTR_OK:
64 LOGGER.error(
"API exception: %s", response.error.message, exc_info=
True)
67 await self.coordinator.async_request_refresh()
74 """Turn off switch."""
UptimeRobotMonitor monitor(self)
None async_turn_on(self, **Any kwargs)
None _async_edit_monitor(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)