Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5af8e7dc5d | |||
| fe073cff55 | |||
| 9053f95bc1 | |||
| a3c5d2db6e | |||
| fc383ff373 | |||
| c295c8848c | |||
| 29f42a75c9 | |||
| 57abb51b13 | |||
| 54b7e9b5d6 | |||
| 24180c9345 | |||
| af0a4a37aa | |||
| a83bae6d3e | |||
| c229ca4b6e |
80
README.md
80
README.md
@@ -10,6 +10,86 @@ Official GeoRide website: https://georide.fr/
|
||||
## Description
|
||||
This component add some sensor for GeoRide Tracker
|
||||
|
||||
### What's entity is available :
|
||||
|
||||
Get GeoRide position
|
||||
Get GeoRide lock status
|
||||
Change GeoRide lock status
|
||||
Get stollen status
|
||||
Get crashed status
|
||||
Get is owner status
|
||||
Get subsription status
|
||||
Get odomoter to km an m (2 entities)
|
||||
Internal battery (of georide 3) (not work on GR1)
|
||||
External battery (of the bike) (not work on GR1)
|
||||
Fixtime (last registered positition of the georide)
|
||||
|
||||
|
||||
### What's events are available:
|
||||
you can filter by data.device_id == XX (XX is your tracker id)
|
||||
you can display your tracker name by by data.device_name
|
||||
|
||||
event;
|
||||
|
||||
georide_position_event
|
||||
georide_lock_event
|
||||
georide_device_event
|
||||
georide_alarm_event
|
||||
|
||||
you can filter with data.type == 'alarm_vibration' to filter by vibration
|
||||
here is the alarm type available: (listen the georide_alarm_event)
|
||||
|
||||
alarm_vibration
|
||||
alarm_exitZone
|
||||
alarm_crash
|
||||
alarm_crashParking
|
||||
alarm_deviceOffline
|
||||
alarm_deviceOnline
|
||||
alarm_powerCut
|
||||
alarm_powerUncut
|
||||
alarm_batteryWarning
|
||||
alarm_temperatureWarning
|
||||
alarm_magnetOn
|
||||
alarm_magnetOff
|
||||
alarm_sonorAlarmOn
|
||||
|
||||
|
||||
## Question:
|
||||
|
||||
### How to have the odometer in Km ? (Deprecated, now you have an entity - thx @Inervo)
|
||||
|
||||
Simply add a sensor like this in configuration.yaml
|
||||
(Replace XX by your tracker id)
|
||||
|
||||
```yaml
|
||||
sensor:
|
||||
- platform: template # Conversion georide de m en km
|
||||
sensors:
|
||||
odometer_XX_km:
|
||||
friendly_name: "Odometter - Km"
|
||||
value_template: "{{ states.sensor.odometer_XX.state | multiply(0.001) | round(3, 'flour') }}"
|
||||
unit_of_measurement: 'Km'
|
||||
```
|
||||
|
||||
### How to use the event:
|
||||
|
||||
Simply made a automation like this:
|
||||
|
||||
```yaml
|
||||
alias: '[TEST] Send notification'
|
||||
description: ''
|
||||
trigger:
|
||||
- platform: event
|
||||
event_type: georide_lock_event
|
||||
condition: []
|
||||
action:
|
||||
- service: notify.mobile_app_oneplus_a3003
|
||||
data:
|
||||
message: 'The device {{ data.device_name }} have recieved a lock event'
|
||||
mode: single
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Options
|
||||
|
||||
|
||||
@@ -290,9 +290,9 @@ class GeoRideContext:
|
||||
|
||||
event_data = {
|
||||
"device_id": tracker.tracker_id,
|
||||
"type": "on_lock",
|
||||
"device_name": tracker.tracker_name
|
||||
}
|
||||
self._hass.bus.async_fire(f"{DOMAIN}_event", event_data)
|
||||
self._hass.bus.async_fire(f"{DOMAIN}_lock_event", event_data)
|
||||
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
coordinator.async_request_refresh(), self._hass.loop
|
||||
@@ -312,9 +312,9 @@ class GeoRideContext:
|
||||
|
||||
event_data = {
|
||||
"device_id": tracker.tracker_id,
|
||||
"type": "on_device",
|
||||
"device_name": tracker.tracker_name,
|
||||
}
|
||||
self._hass.bus.async_fire(f"{DOMAIN}_event", event_data)
|
||||
self._hass.bus.async_fire(f"{DOMAIN}_device_event", event_data)
|
||||
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
coordinator.async_request_refresh(), self._hass.loop
|
||||
@@ -329,28 +329,41 @@ class GeoRideContext:
|
||||
tracker = coordoned_tracker['tracker_device'].tracker
|
||||
coordinator = coordoned_tracker['coordinator']
|
||||
if tracker.tracker_id == data['trackerId']:
|
||||
if data.name == 'vibration':
|
||||
if data['name'] == 'vibration':
|
||||
_LOGGER.info("Vibration detected")
|
||||
elif data.name == 'exitZone':
|
||||
elif data['name'] == 'exitZone':
|
||||
_LOGGER.info("Exit zone detected")
|
||||
elif data.name == 'crash':
|
||||
elif data['name'] == 'crash':
|
||||
_LOGGER.info("Crash detected")
|
||||
elif data.name == 'crashParking':
|
||||
elif data['name'] == 'crashParking':
|
||||
_LOGGER.info("Crash parking detected")
|
||||
elif data.name == 'deviceOffline':
|
||||
elif data['name'] == 'deviceOffline':
|
||||
_LOGGER.info("Device offline detected")
|
||||
elif data.name == 'deviceOnline':
|
||||
elif data['name'] == 'deviceOnline':
|
||||
_LOGGER.info("Device online detected")
|
||||
elif data.name == 'powerCut':
|
||||
elif data['name'] == 'powerCut':
|
||||
_LOGGER.info("powerCut detected")
|
||||
elif data['name'] == 'powerUncut':
|
||||
_LOGGER.info("powerUncut detected")
|
||||
elif data['name'] == 'batteryWarning':
|
||||
_LOGGER.info("batteryWarning detected")
|
||||
elif data['name'] == 'temperatureWarning':
|
||||
_LOGGER.info("temperatureWarning detected")
|
||||
elif data['name'] == 'magnetOn':
|
||||
_LOGGER.info("magnetOn detected")
|
||||
elif data['name'] == 'magnetOff':
|
||||
_LOGGER.info("magnetOff detected")
|
||||
elif data['name'] == 'sonorAlarmOn':
|
||||
_LOGGER.info("sonorAlarmOn detected")
|
||||
else:
|
||||
_LOGGER.warning("Unamanged alarm: %s", data.name)
|
||||
_LOGGER.warning("Unmanaged alarm: %s", data["name"])
|
||||
|
||||
event_data = {
|
||||
"device_id": tracker.tracker_id,
|
||||
"type": f"alarm_{data.name}",
|
||||
"device_name": tracker.tracker_name,
|
||||
"type": f"alarm_{data['name']}"
|
||||
}
|
||||
self._hass.bus.async_fire(f"{DOMAIN}_event", event_data)
|
||||
self._hass.bus.async_fire(f"{DOMAIN}_alarm_event", event_data)
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
coordinator.async_request_refresh(), self._hass.loop
|
||||
).result()
|
||||
@@ -372,9 +385,9 @@ class GeoRideContext:
|
||||
|
||||
event_data = {
|
||||
"device_id": tracker.tracker_id,
|
||||
"type": "position",
|
||||
"device_name": tracker.tracker_name
|
||||
}
|
||||
self._hass.bus.async_fire(f"{DOMAIN}_event", event_data)
|
||||
self._hass.bus.async_fire(f"{DOMAIN}_position_event", event_data)
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
coordinator.async_request_refresh(), self._hass.loop
|
||||
).result()
|
||||
|
||||
@@ -30,6 +30,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
|
||||
entities.append(GeoRideCrashedBinarySensorEntity(coordinator, tracker_device))
|
||||
entities.append(GeoRideOwnerBinarySensorEntity(coordinator, tracker_device))
|
||||
entities.append(GeoRideActiveSubscriptionBinarySensorEntity(coordinator, tracker_device))
|
||||
entities.append(GeoRideNetworkBinarySensorEntity(coordinator, tracker_device))
|
||||
entities.append(GeoRideMovingBinarySensorEntity(coordinator, tracker_device))
|
||||
|
||||
hass.data[GEORIDE_DOMAIN]["devices"][tracker_device.tracker.tracker_id] = coordinator
|
||||
|
||||
@@ -68,6 +70,11 @@ class GeoRideStolenBinarySensorEntity(GeoRideBinarySensorEntity):
|
||||
"""Return the unique ID."""
|
||||
return f"is_stolen_{self._tracker_device.tracker.tracker_id}"
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class."""
|
||||
return "problem"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""state value property"""
|
||||
@@ -93,6 +100,11 @@ class GeoRideCrashedBinarySensorEntity(GeoRideBinarySensorEntity):
|
||||
"""Return the unique ID."""
|
||||
return f"is_crashed_{self._tracker_device.tracker.tracker_id}"
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class."""
|
||||
return "problem"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""state value property"""
|
||||
@@ -154,4 +166,63 @@ class GeoRideOwnerBinarySensorEntity(GeoRideBinarySensorEntity):
|
||||
def name(self):
|
||||
""" GeoRide odometer name """
|
||||
return f"{self._name} is own tracker"
|
||||
|
||||
|
||||
class GeoRideNetworkBinarySensorEntity(GeoRideBinarySensorEntity):
|
||||
"""Represent a tracked device."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator[Mapping[str, Any]],
|
||||
tracker_device: Device):
|
||||
"""Set up Georide entity."""
|
||||
super().__init__(coordinator, tracker_device)
|
||||
self.entity_id = f"{ENTITY_ID_FORMAT.format('have_network')}.{tracker_device.tracker.tracker_id}"# pylint: disable=C0301
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique ID."""
|
||||
return f"have_network_{self._tracker_device.tracker.tracker_id}"
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class."""
|
||||
return "connectivity"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""state value property"""
|
||||
if self._tracker_device.tracker.status == "online":
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" GeoRide name """
|
||||
return f"{self._name} have network"
|
||||
|
||||
class GeoRideMovingBinarySensorEntity(GeoRideBinarySensorEntity):
|
||||
"""Represent a tracked device."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator[Mapping[str, Any]],
|
||||
tracker_device: Device):
|
||||
"""Set up Georide entity."""
|
||||
super().__init__(coordinator, tracker_device)
|
||||
self.entity_id = f"{ENTITY_ID_FORMAT.format('moving')}.{tracker_device.tracker.tracker_id}"# pylint: disable=C0301
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique ID."""
|
||||
return f"moving_{self._tracker_device.tracker.tracker_id}"
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class."""
|
||||
return "moving"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""state value property"""
|
||||
return self._tracker_device.tracker.moving
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" GeoRide name """
|
||||
return f"{self._name} is moving"
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
"config_flow": true,
|
||||
"documentation": "https://github.com/ptimatth/GeorideHA",
|
||||
"requirements": [
|
||||
"georideapilib>=0.6.0",
|
||||
"georideapilib>=0.6.1",
|
||||
"pyjwt>=1.7.1"
|
||||
],
|
||||
"dependencies": [],
|
||||
"codeowners": ["ptimatth"],
|
||||
"version": "0.6.0"
|
||||
"version": "0.8.0"
|
||||
}
|
||||
@@ -27,9 +27,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
|
||||
for coordoned_tracker in coordoned_trackers:
|
||||
tracker_device = coordoned_tracker['tracker_device']
|
||||
coordinator = coordoned_tracker['coordinator']
|
||||
entity = GeoRideOdometerSensorEntity(coordinator, tracker_device, hass)
|
||||
hass.data[GEORIDE_DOMAIN]["devices"][tracker_device.tracker.tracker_id] = coordinator
|
||||
entities.append(entity)
|
||||
entities.append(GeoRideOdometerSensorEntity(coordinator, tracker_device, hass))
|
||||
entities.append(GeoRideOdometerKmSensorEntity(coordinator, tracker_device, hass))
|
||||
entities.append(GeoRideInternalBatterySensorEntity(coordinator, tracker_device))
|
||||
entities.append(GeoRideExternalBatterySensorEntity(coordinator, tracker_device))
|
||||
entities.append(GeoRideFixtimeSensorEntity(coordinator, tracker_device))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
@@ -58,7 +61,8 @@ class GeoRideOdometerSensorEntity(CoordinatorEntity, SensorEntity):
|
||||
@property
|
||||
def state(self):
|
||||
"""state property"""
|
||||
return self._tracker_device.tracker.odometer
|
||||
odometer = self._tracker_device.tracker.odometer
|
||||
return odometer
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
@@ -79,3 +83,176 @@ class GeoRideOdometerSensorEntity(CoordinatorEntity, SensorEntity):
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
return self._tracker_device.device_info
|
||||
|
||||
class GeoRideOdometerKmSensorEntity(CoordinatorEntity, SensorEntity):
|
||||
"""Represent a tracked device."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator[Mapping[str, Any]],
|
||||
tracker_device:Device, hass):
|
||||
"""Set up GeoRide entity."""
|
||||
super().__init__(coordinator)
|
||||
self._tracker_device = tracker_device
|
||||
self._name = tracker_device.tracker.tracker_name
|
||||
self._unit_of_measurement = "km"
|
||||
self.entity_id = f"{ENTITY_ID_FORMAT.format('odometer_km')}.{tracker_device.tracker.tracker_id}"# pylint: disable=C0301
|
||||
|
||||
self._state = 0
|
||||
self._hass = hass
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique ID."""
|
||||
return f"odometer_km_{self._tracker_device.tracker.tracker_id}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""state property"""
|
||||
odometer = self._tracker_device.tracker.odometer // 1000
|
||||
return odometer
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""unit of mesurment property"""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" GeoRide odometer name """
|
||||
return f"{self._name} odometer km"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""icon getter"""
|
||||
return "mdi:counter"
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
return self._tracker_device.device_info
|
||||
|
||||
class GeoRideInternalBatterySensorEntity(CoordinatorEntity, SensorEntity):
|
||||
"""Represent a tracked device."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator[Mapping[str, Any]],
|
||||
tracker_device:Device):
|
||||
"""Set up GeoRide entity."""
|
||||
super().__init__(coordinator)
|
||||
self._tracker_device = tracker_device
|
||||
self._name = tracker_device.tracker.tracker_name
|
||||
self._unit_of_measurement = "V"
|
||||
self.entity_id = f"{ENTITY_ID_FORMAT.format('internal_battery_voltage')}.{tracker_device.tracker.tracker_id}"# pylint: disable=C0301
|
||||
|
||||
self._state = 0
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique ID."""
|
||||
return f"internal_battery_voltage_{self._tracker_device.tracker.tracker_id}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""state property"""
|
||||
return self._tracker_device.tracker.internal_battery_voltage
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""unit of mesurment property"""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" GeoRide internal_battery_voltage name """
|
||||
return f"{self._name} internal_battery_voltage"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""icon getter"""
|
||||
return "mdi:battery"
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
return self._tracker_device.device_info
|
||||
|
||||
class GeoRideExternalBatterySensorEntity(CoordinatorEntity, SensorEntity):
|
||||
"""Represent a tracked device."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator[Mapping[str, Any]],
|
||||
tracker_device:Device):
|
||||
"""Set up GeoRide entity."""
|
||||
super().__init__(coordinator)
|
||||
self._tracker_device = tracker_device
|
||||
self._name = tracker_device.tracker.tracker_name
|
||||
self._unit_of_measurement = "V"
|
||||
self.entity_id = f"{ENTITY_ID_FORMAT.format('external_battery_voltage')}.{tracker_device.tracker.tracker_id}"# pylint: disable=C0301
|
||||
|
||||
self._state = 0
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique ID."""
|
||||
return f"external_battery_voltage_{self._tracker_device.tracker.tracker_id}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""state property"""
|
||||
return self._tracker_device.tracker.external_battery_voltage
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""unit of mesurment property"""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" GeoRide internal_battery_voltage name """
|
||||
return f"{self._name} external_battery_voltage"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""icon getter"""
|
||||
return "mdi:battery"
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
return self._tracker_device.device_info
|
||||
|
||||
class GeoRideFixtimeSensorEntity(CoordinatorEntity, SensorEntity):
|
||||
"""Represent a tracked device."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator[Mapping[str, Any]],
|
||||
tracker_device:Device):
|
||||
"""Set up GeoRide entity."""
|
||||
super().__init__(coordinator)
|
||||
self._tracker_device = tracker_device
|
||||
self._name = tracker_device.tracker.tracker_name
|
||||
self.entity_id = f"{ENTITY_ID_FORMAT.format('fixtime')}.{tracker_device.tracker.tracker_id}"# pylint: disable=C0301
|
||||
|
||||
self._state = 0
|
||||
self._device_class = "timestamp"
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique ID."""
|
||||
return f"fixtime_{self._tracker_device.tracker.tracker_id}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""state property"""
|
||||
return self._tracker_device.tracker.fixtime
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" GeoRide fixtime name """
|
||||
return f"{self._name} last fixed position"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""icon getter"""
|
||||
return "mdi:map-clock"
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
return self._tracker_device.device_info
|
||||
|
||||
@@ -58,7 +58,7 @@ class GeoRideLockSwitchEntity(CoordinatorEntity, SwitchEntity):
|
||||
success = await self._hass.async_add_executor_job(GeoRideApi.lock_tracker,
|
||||
token, self._tracker_device.tracker.tracker_id)
|
||||
if success:
|
||||
self._tracker.is_locked = True
|
||||
self._tracker_device.tracker.is_locked = True
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
""" unlock the GeoRide tracker """
|
||||
@@ -68,7 +68,7 @@ class GeoRideLockSwitchEntity(CoordinatorEntity, SwitchEntity):
|
||||
success = await self._hass.async_add_executor_job(GeoRideApi.unlock_tracker,
|
||||
token, self._tracker_device.tracker.tracker_id)
|
||||
if success:
|
||||
self._tracker.is_locked = False
|
||||
self._tracker_device.tracker.is_locked = False
|
||||
|
||||
async def async_toggle(self, **kwargs):
|
||||
""" toggle lock the georide tracker """
|
||||
@@ -77,7 +77,7 @@ class GeoRideLockSwitchEntity(CoordinatorEntity, SwitchEntity):
|
||||
token = await georide_context.get_token()
|
||||
result = await self._hass.async_add_executor_job(GeoRideApi.toogle_lock_tracker,
|
||||
token, self._tracker_device.tracker.tracker_id)
|
||||
self._tracker.is_locked = result
|
||||
self._tracker_device.tracker.is_locked = result
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
||||
Reference in New Issue
Block a user