Update to to latest georideapilib

develop
Matthieu DUVAL 2 years ago
parent b8c8bcba14
commit 7ea6c96331

@ -44,11 +44,8 @@ from .const import (
SIREN_ACTIVATION_DELAY SIREN_ACTIVATION_DELAY
) )
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema( CONFIG_SCHEMA = vol.Schema(
{ {
vol.Required(DOMAIN, default={}): { vol.Required(DOMAIN, default={}): {
@ -59,7 +56,6 @@ CONFIG_SCHEMA = vol.Schema(
extra=vol.ALLOW_EXTRA, extra=vol.ALLOW_EXTRA,
) )
async def async_setup(hass, config): async def async_setup(hass, config):
"""Setup GeoRide component.""" """Setup GeoRide component."""
hass.data[DOMAIN] = {"config": config[DOMAIN], "devices": {}, "unsub": None} hass.data[DOMAIN] = {"config": config[DOMAIN], "devices": {}, "unsub": None}
@ -76,7 +72,6 @@ async def async_setup(hass, config):
# Return boolean to indicate that initialization was successful. # Return boolean to indicate that initialization was successful.
return True return True
async def async_setup_entry(hass, entry): async def async_setup_entry(hass, entry):
"""Set up GeoRide entry.""" """Set up GeoRide entry."""
config = hass.data[DOMAIN]["config"] config = hass.data[DOMAIN]["config"]
@ -111,7 +106,7 @@ async def async_setup_entry(hass, entry):
return True return True
async def async_unload_entry(hass, entry): async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload an GeoRide config entry.""" """Unload an GeoRide config entry."""
await hass.config_entries.async_forward_entry_unload(entry, "device_tracker") await hass.config_entries.async_forward_entry_unload(entry, "device_tracker")
@ -120,9 +115,22 @@ async def async_unload_entry(hass, entry):
await hass.config_entries.async_forward_entry_unload(entry, "binary_sensor") await hass.config_entries.async_forward_entry_unload(entry, "binary_sensor")
await hass.config_entries.async_forward_entry_unload(entry, "siren") await hass.config_entries.async_forward_entry_unload(entry, "siren")
context = hass.data[DOMAIN]["context"]
context.socket.disconnect() // Disconnect only if all devices is disabled
return True
async def async_remove_config_entry_device(hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry) -> bool:
"""Remove an GeoRide device entry."""
await hass.config_entries.async_remove_config_entry_device(device_entry, "device_tracker")
await hass.config_entries.async_remove_config_entry_device(device_entry, "switch")
await hass.config_entries.async_remove_config_entry_device(device_entry, "sensor")
await hass.config_entries.async_remove_config_entry_device(device_entry, "binary_sensor")
await hass.config_entries.async_remove_config_entry_device(device_entry, "siren")
context = hass.data[DOMAIN]["context"] context = hass.data[DOMAIN]["context"]
context.socket.disconnect() # context.socket.disconnect()
return True return True

@ -12,7 +12,7 @@ from .const import CONF_EMAIL, CONF_PASSWORD, CONF_TOKEN, DOMAIN
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@config_entries.HANDLERS.register("georide") @config_entries.HANDLERS.register(DOMAIN)
class GeoRideConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): class GeoRideConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""GeoRide config flow """ """GeoRide config flow """
@ -37,8 +37,6 @@ class GeoRideConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
vol.Required(CONF_PASSWORD): vol.All(str) vol.Required(CONF_PASSWORD): vol.All(str)
})) }))
async def async_step_georide_login(self, user_input): async def async_step_georide_login(self, user_input):
""" try to seupt GeoRide Account """ """ try to seupt GeoRide Account """

@ -10,6 +10,7 @@ class Device:
"""Initialize GeoRideTracker device.""" """Initialize GeoRideTracker device."""
self._tracker: GeoRideTracker = tracker self._tracker: GeoRideTracker = tracker
@property @property
def tracker(self): def tracker(self):
"""return the tracker""" """return the tracker"""
@ -20,11 +21,26 @@ class Device:
"""Get the name.""" """Get the name."""
return self._tracker.tracker_name return self._tracker.tracker_name
@property
def default_manufacturer(self) -> str:
"""Get the default_manufacturer."""
return "GeoRide"
@property @property
def manufacturer(self) -> str: def manufacturer(self) -> str:
"""Get the manufacturer.""" """Get the manufacturer."""
return "GeoRide" return "GeoRide"
@property
def default_model(self) -> str:
"""Get the default model."""
return "GeoRide 1"
@property
def suggested_area(self) -> str:
"""Get the suggested_area."""
return "Garage"
@property @property
def model_name(self) -> str: def model_name(self) -> str:
"""Get the model name.""" """Get the model name."""
@ -34,28 +50,42 @@ class Device:
elif self._tracker.version == 2: elif self._tracker.version == 2:
name = "GeoRide 2" name = "GeoRide 2"
elif self._tracker.version == 3: elif self._tracker.version == 3:
name = "GeoRide 3" if self._tracker.model == 'georide-3':
name = "GeoRide 3"
else:
name = "GeoRide Mini"
else: else:
name = "Prototype / Unknown" name = "Prototype / Unknown"
return name return name
@property
def sw_version(self) -> str:
"""Get the software version."""
return str(self._tracker.software_version)
@property
def hw_version(self) -> str:
"""Get the hardware version."""
return str(self._tracker.version)
@property
def unique_id(self) -> str:
"""Get the unique id."""
return {(GEORIDE_DOMAIN, self._tracker.tracker_id)}
@property @property
def device_info(self): def device_info(self):
"""Return the device info.""" """Return the device info."""
return { return {
"name": self.name, "name": self.name,
"identifiers": self.unique_id, "identifiers": self.unique_id,
"manufacturer": "GeoRide", "manufacturer": self.manufacturer,
"model": self.model_name, "model": self.model_name,
"suggested_area": "Garage" "suggested_area": self.suggested_area,
"sw_version" : self.sw_version,
"hw_version": self.hw_version
} }
@property
def unique_id(self) -> str:
"""Get the unique id."""
return {(GEORIDE_DOMAIN, self._tracker.tracker_id)}
def __str__(self) -> str: def __str__(self) -> str:
"""Get string representation.""" """Get string representation."""
return f"GeoRide Device: {self.name}::{self.model_name}::{self.unique_id}" return f"GeoRide Device: {self.name}::{self.model_name}::{self.unique_id}"
@ -77,34 +107,54 @@ class DeviceBeacon:
"""Get the name.""" """Get the name."""
return self._beacon.name return self._beacon.name
@property
def default_manufacturer(self) -> str:
"""Get the default_manufacturer."""
return "GeoRide"
@property @property
def manufacturer(self) -> str: def manufacturer(self) -> str:
"""Get the manufacturer.""" """Get the manufacturer."""
return "GeoRide" return "GeoRide"
@property
def default_model(self) -> str:
"""Get the default model."""
return "GeoRide Beacon"
@property
def suggested_area(self) -> str:
"""Get the suggested_area."""
return "Garage"
@property @property
def model_name(self) -> str: def model_name(self) -> str:
"""Get the model name.""" """Get the model name."""
name = "GeoRide Beacon" name = "GeoRide Beacon"
return name return name
@property
def unique_id(self) -> str:
"""Get the unique id."""
return {(GEORIDE_DOMAIN, self._beacon.beacon_id)}
@property
def via_device(self) -> str:
"""Get the unique id."""
return {(GEORIDE_DOMAIN, self._beacon.tracker_id)}
@property @property
def device_info(self): def device_info(self):
"""Return the device info.""" """Return the device info."""
return { return {
"name": self.name, "name": self.name,
"identifiers": self.unique_id, "identifiers": self.unique_id,
"manufacturer": "GeoRide", "manufacturer": self.manufacturer,
"model": self.model_name, "model": self.model_name,
"suggested_area": "Garage" "suggested_area": self.suggested_area,
"via_device": self.via_device
} }
@property
def unique_id(self) -> str:
"""Get the unique id."""
return {(GEORIDE_DOMAIN, self._beacon.beacon_id)}
def __str__(self) -> str: def __str__(self) -> str:
"""Get string representation.""" """Get string representation."""
return f"GeoRide Device: {self.name}::{self.model_name}::{self.unique_id}" return f"GeoRide Device: {self.name}::{self.model_name}::{self.unique_id}"

@ -6,10 +6,10 @@
"issue_tracker": "https://github.com/ptimatth/GeorideHA/issues", "issue_tracker": "https://github.com/ptimatth/GeorideHA/issues",
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"requirements": [ "requirements": [
"georideapilib>=0.8.4", "georideapilib>=0.9.0",
"pyjwt>=2.2.0" "pyjwt>=2.2.0"
], ],
"dependencies": [], "dependencies": [],
"codeowners": ["ptimatth"], "codeowners": ["ptimatth"],
"version": "0.9.0" "version": "1.0.0"
} }

@ -4,5 +4,5 @@
"render_readme": true, "render_readme": true,
"domains": ["devices_tracker", "sensor"], "domains": ["devices_tracker", "sensor"],
"country": ["FR"], "country": ["FR"],
"homeassistant": "2022.2.0" "homeassistant": "2023.2.0"
} }
Loading…
Cancel
Save