Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 rollback & fix login missin password #224

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions custom_components/xplora_watch/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def __init__(
super().__init__(config_entry, description, coordinator, ward, sw_version, wuid)
if self.watch_uid not in self.coordinator.data:
return
self._watch_data: dict[str, any] = self.coordinator.data[self.watch_uid]

i = (self._options.get(CONF_WATCHES, []).index(wuid) + 1) if self._options.get(CONF_WATCHES, []) else -1
if i == -1:
Expand Down Expand Up @@ -126,13 +125,13 @@ def __init__(
def is_on(self) -> bool | None:
"""Return true if the binary sensor is on."""
if self.entity_description.key == BINARY_SENSOR_CHARGING:
return self._watch_data.get("isCharging", None)
return self.coordinator.data[self.watch_uid].get("isCharging", None)
if self.entity_description.key == BINARY_SENSOR_STATE:
return self._watch_data.get("isOnline", None)
return self.coordinator.data[self.watch_uid].get("isOnline", None)
if self.entity_description.key == BINARY_SENSOR_SAFEZONE:
if self._options.get(CONF_HOME_SAFEZONE, STATE_OFF) == STATE_ON:
latitude = self._watch_data.get(ATTR_TRACKER_LAT, None)
longitude = self._watch_data.get(ATTR_TRACKER_LNG, None)
latitude = self.coordinator.data[self.watch_uid].get(ATTR_TRACKER_LAT, None)
longitude = self.coordinator.data[self.watch_uid].get(ATTR_TRACKER_LNG, None)
home_latitude = self.hass.states.get(HOME).attributes[ATTR_LATITUDE]
home_longitude = self.hass.states.get(HOME).attributes[ATTR_LONGITUDE]
home_raduis = self.hass.states.get(HOME).attributes["radius"]
Expand All @@ -145,13 +144,15 @@ def is_on(self) -> bool | None:
self._options.get(CONF_HOME_RADIUS, home_raduis),
):
return False
return self._watch_data.get("isSafezone", None)
return self.coordinator.data[self.watch_uid].get("isSafezone", None)
return False

@property
def icon(self) -> str | None:
"""Return the icon to use in the frontend, if any."""
if self.entity_description.key == BINARY_SENSOR_CHARGING and not self._watch_data.get("isCharging", None):
if self.entity_description.key == BINARY_SENSOR_CHARGING and not self.coordinator.data[self.watch_uid].get(
"isCharging", None
):
return "mdi:battery-unknown"
if hasattr(self, "_attr_icon"):
return self._attr_icon
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xplora_watch/const_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)

DEFAULT_DATA_SCHEMA = {
vol.Required(CONF_PASSWORD): TextSelector(TextSelectorConfig(type=TextSelectorType.PASSWORD)),
vol.Required(CONF_TIMEZONE, default="Europe/Berlin"): TextSelector(TextSelectorConfig(type=TextSelectorType.TEXT)),
vol.Required(CONF_USERLANG, default="en-GB"): SelectSelector(
SelectSelectorConfig(
Expand Down Expand Up @@ -63,6 +64,5 @@
}
DATA_SCHEMA_EMAIL = {
vol.Required(CONF_EMAIL): TextSelector(TextSelectorConfig(type=TextSelectorType.EMAIL)),
vol.Required(CONF_PASSWORD): TextSelector(TextSelectorConfig(type=TextSelectorType.PASSWORD)),
**DEFAULT_DATA_SCHEMA,
}
35 changes: 20 additions & 15 deletions custom_components/xplora_watch/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ def __init__(
super().__init__(config_entry, None, coordinator, ward, sw_version, wuid)
if self.watch_uid not in self.coordinator.data:
return
self._watch_data: dict[str, any] = self.coordinator.data[self.watch_uid]

self._hass = hass
i = (self._options.get(CONF_WATCHES, []).index(wuid) + 1) if self._options.get(CONF_WATCHES, []) else -1
Expand All @@ -182,17 +181,17 @@ def __init__(
@property
def battery_level(self) -> int | None:
"""Return battery value of the device."""
return self._watch_data.get(ATTR_BATTERY, None)
return self.coordinator.data[self.watch_uid].get(ATTR_BATTERY, None)

@property
def latitude(self) -> float | None:
"""Return latitude value of the device."""
return self._watch_data.get(ATTR_TRACKER_LAT, None)
return self.coordinator.data[self.watch_uid].get(ATTR_TRACKER_LAT, None)

@property
def longitude(self) -> float | None:
"""Return longitude value of the device."""
return self._watch_data.get(ATTR_TRACKER_LNG, None)
return self.coordinator.data[self.watch_uid].get(ATTR_TRACKER_LNG, None)

@property
def source_type(self) -> SourceType | str:
Expand All @@ -202,38 +201,44 @@ def source_type(self) -> SourceType | str:
@property
def location_accuracy(self) -> int:
"""Return the gps accuracy of the device."""
return self._watch_data.get("location_accuracy", 0)
return self.coordinator.data[self.watch_uid].get("location_accuracy", 0)

@property
def address(self) -> str | None:
"""Return a location name for the current location of the device."""
return self._watch_data.get(ATTR_LOCATION_NAME, None)
return self.coordinator.data[self.watch_uid].get(ATTR_LOCATION_NAME, None)

@property
def entity_picture(self) -> str | None:
"""Return the entity picture to use in the frontend, if any."""
return self._watch_data.get("entity_picture", None)
return self.coordinator.data[self.watch_uid].get("entity_picture", None)

@property
def extra_state_attributes(self) -> dict[str, any]:
data = super().extra_state_attributes or {}
distance_to_home = None

if self._watch_data.get(ATTR_TRACKER_LAT, None) and self._watch_data.get(ATTR_TRACKER_LNG, None):
if self.coordinator.data[self.watch_uid].get(ATTR_TRACKER_LAT, None) and self.coordinator.data[self.watch_uid].get(
ATTR_TRACKER_LNG, None
):
lat_lng: tuple[float, float] = (
float(self._watch_data.get(ATTR_TRACKER_LAT, None)),
float(self._watch_data.get(ATTR_TRACKER_LNG, None)),
float(self.coordinator.data[self.watch_uid].get(ATTR_TRACKER_LAT, None)),
float(self.coordinator.data[self.watch_uid].get(ATTR_TRACKER_LNG, None)),
)
distance_to_home = get_location_distance_meter(self._hass, lat_lng)

return dict(
data,
**{
ATTR_TRACKER_DISTOHOME: distance_to_home,
ATTR_TRACKER_ADDR: self._watch_data.get(ATTR_LOCATION_NAME, None) if distance_to_home else None,
ATTR_TRACKER_LAST_TRACK: self._watch_data.get("lastTrackTime", None) if distance_to_home else None,
ATTR_TRACKER_IMEI: self._watch_data.get(ATTR_TRACKER_IMEI, None),
ATTR_TRACKER_POI: self._watch_data.get(ATTR_TRACKER_POI, None),
ATTR_TRACKER_LICENCE: self._watch_data.get(ATTR_TRACKER_LICENCE, None),
ATTR_TRACKER_ADDR: self.coordinator.data[self.watch_uid].get(ATTR_LOCATION_NAME, None)
if distance_to_home
else None,
ATTR_TRACKER_LAST_TRACK: self.coordinator.data[self.watch_uid].get("lastTrackTime", None)
if distance_to_home
else None,
ATTR_TRACKER_IMEI: self.coordinator.data[self.watch_uid].get(ATTR_TRACKER_IMEI, None),
ATTR_TRACKER_POI: self.coordinator.data[self.watch_uid].get(ATTR_TRACKER_POI, None),
ATTR_TRACKER_LICENCE: self.coordinator.data[self.watch_uid].get(ATTR_TRACKER_LICENCE, None),
},
)
2 changes: 1 addition & 1 deletion custom_components/xplora_watch/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def async_will_remove_from_hass(self) -> None:
await super().async_will_remove_from_hass()
for unsub in self._unsub_dispatchers:
unsub()
_LOGGER.debug("When entity is remove on hass.")
_LOGGER.debug("When entity is remove on hass")
self._unsub_dispatchers = []

@callback
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xplora_watch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"pydub",
"marshmallow-enum"
],
"version": "v2.8.1"
"version": "v2.8.2"
}
21 changes: 10 additions & 11 deletions custom_components/xplora_watch/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def __init__(
super().__init__(config_entry, description, coordinator, ward, sw_version, wuid)
if self.watch_uid not in self.coordinator.data:
return
self._watch_data: dict[str, any] = self.coordinator.data[self.watch_uid]

i = (self._options.get(CONF_WATCHES, []).index(wuid) + 1) if self._options.get(CONF_WATCHES, []) else -1
if i == -1:
Expand All @@ -135,16 +134,16 @@ def __init__(
@property
def native_value(self) -> StateType:
if self.entity_description.key == SENSOR_BATTERY:
return self._watch_data.get(SENSOR_BATTERY, None)
return self.coordinator.data[self.watch_uid].get(SENSOR_BATTERY, None)
if self.entity_description.key == SENSOR_STEP_DAY:
return self._watch_data.get(SENSOR_STEP_DAY, 0)
return self.coordinator.data[self.watch_uid].get(SENSOR_STEP_DAY, 0)
if self.entity_description.key == SENSOR_XCOIN:
return self._watch_data.get(SENSOR_XCOIN, 0)
return self.coordinator.data[self.watch_uid].get(SENSOR_XCOIN, 0)
if self.entity_description.key == SENSOR_MESSAGE:
return self._watch_data.get("unreadMsg", 0)
return self.coordinator.data[self.watch_uid].get("unreadMsg", 0)
if self.entity_description.key == SENSOR_DISTANCE:
lat = self._watch_data.get(ATTR_TRACKER_LAT, None)
lng = self._watch_data.get(ATTR_TRACKER_LNG, None)
lat = self.coordinator.data[self.watch_uid].get(ATTR_TRACKER_LAT, None)
lng = self.coordinator.data[self.watch_uid].get(ATTR_TRACKER_LNG, None)
if lat and lng:
lat_lng: tuple[float, float] = (float(lat), float(lng))
return get_location_distance_meter(self.hass, lat_lng)
Expand All @@ -157,9 +156,9 @@ def extra_state_attributes(self) -> dict[str, any]:
if (
self.entity_description.key is SENSOR_MESSAGE
and self.coordinator.data
or self.coordinator.data.get(self.watch_uid, None)
or SENSOR_MESSAGE in self._watch_data
or self._watch_data.get(SENSOR_MESSAGE, None)
and self.coordinator.data.get(self.watch_uid, None)
and SENSOR_MESSAGE in self.coordinator.data[self.watch_uid]
and self.coordinator.data[self.watch_uid].get(SENSOR_MESSAGE, None)
):
return dict(data, **self._watch_data.get(SENSOR_MESSAGE))
return dict(data, **self.coordinator.data[self.watch_uid].get(SENSOR_MESSAGE))
return dict(data, **{})
11 changes: 5 additions & 6 deletions custom_components/xplora_watch/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def __init__(
super().__init__(config_entry, description, coordinator, ward, sw_version, wuid)
if self.watch_uid not in self.coordinator.data:
return
self._watch_data: dict[str, any] = self.coordinator.data[self.watch_uid]

self._alarm = alarm
i = (self._options.get(CONF_WATCHES, []).index(wuid) + 1) if self._options.get(CONF_WATCHES, []) else -1
Expand Down Expand Up @@ -124,8 +123,8 @@ def __init__(
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._watch_data = self.coordinator.data[self.watch_uid]
for alarm in self._watch_data.get("alarm", []):
self.coordinator.data[self.watch_uid] = self.coordinator.data[self.watch_uid]
for alarm in self.coordinator.data[self.watch_uid].get("alarm", []):
if alarm[ATTR_ID] == self._alarm[ATTR_ID]:
self._attr_is_on = self._states(alarm["status"])
self.async_write_ha_state()
Expand Down Expand Up @@ -180,7 +179,7 @@ def __init__(
super().__init__(config_entry, description, coordinator, ward, sw_version, wuid)
if self.watch_uid not in self.coordinator.data:
return
self._watch_data: dict[str, any] = self.coordinator.data[self.watch_uid]
self.coordinator.data[self.watch_uid]: dict[str, any] = self.coordinator.data[self.watch_uid]

self._silent = silent
i = (self._options.get(CONF_WATCHES, []).index(wuid) + 1) if self._options.get(CONF_WATCHES, []) else -1
Expand Down Expand Up @@ -216,8 +215,8 @@ def __init__(
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._watch_data = self.coordinator.data[self.watch_uid]
for silent in self._watch_data.get("silent", []):
self.coordinator.data[self.watch_uid] = self.coordinator.data[self.watch_uid]
for silent in self.coordinator.data[self.watch_uid].get("silent", []):
if silent[ATTR_ID] == self._silent[ATTR_ID]:
self._attr_is_on = self._states(silent["status"])
self.async_write_ha_state()
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "Xplora® Watch",
"country": ["DE", "US"],
"render_readme": true,
"homeassistant": "2023.6.0",
"homeassistant": "2023.6.1",
"hacs": "1.32.1"
}