def update(self):
Get updated status from API.
try:
status = requests.get(
"{}/jc".format(self.opengarage_url), timeout=10
).json()
except requests.exceptions.RequestException as ex:
_LOGGER.error(
"Unable to connect to OpenGarage device: %(reason)s", dict(reason=ex)
)
self._available = False
return
if self._name is None and status["name"] is not None:
self._name = status["name"]
state = STATES_MAP.get(status.get("door"))
if self._state_before_move is not None:
if self._state_before_move != state:
self._state = state
self._state_before_move = None
else:
self._state = state
_LOGGER.debug("%s status: %s", self._name, self._state)
if status.get("rssi") is not None:
self._device_state_attributes[ATTR_SIGNAL_STRENGTH] = status.get("rssi")
if status.get("dist") is not None:
self._device_state_attributes[ATTR_DISTANCE_SENSOR] = status.get("dist")
if self._state is not None:
self._device_state_attributes[ATTR_DOOR_STATE] = self._state