Compare commits

..

13 Commits
0.6.1 ... 0.8.1

Author SHA1 Message Date
e59c8cb195 Shipping v0.8.1 2021-10-10 13:09:57 +02:00
b17f38ee66 Fix #4 jwt decode afater update of hA to pyjwt 2.1.0 2021-10-10 13:06:26 +02:00
5af8e7dc5d Shipping v0.8.0, thx to @Inervo 2021-08-30 20:14:56 +02:00
fe073cff55 Merge PR #3 2021-08-30 20:09:10 +02:00
9053f95bc1 Shipping v0.7.2 2021-07-13 20:37:32 +02:00
a3c5d2db6e Fix data.name unsted of data['name'] 2021-07-13 20:36:19 +02:00
fc383ff373 Shipping v0.7.1 2021-07-05 18:42:57 +02:00
c295c8848c Change version 2021-07-05 18:41:22 +02:00
29f42a75c9 Fix alarm event trigger 2021-07-05 18:39:07 +02:00
57abb51b13 Shipping 0.7.0 2021-07-01 11:54:45 +02:00
54b7e9b5d6 Setup ne device event on georide Ha 2021-07-01 11:54:03 +02:00
24180c9345 Shipping v0.6.2 2021-05-05 22:56:38 +02:00
af0a4a37aa Bump georideapilib min version to v0.6.1 2021-05-05 22:53:52 +02:00
6 changed files with 366 additions and 25 deletions

View File

@@ -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

View File

@@ -184,7 +184,7 @@ class GeoRideContext:
async def get_token(self):
""" here we return the current valid tocken """
jwt_data = jwt.decode(self._token, verify=False)
jwt_data = jwt.decode(self._token, options={"verify_signature": False})
exp_timestamp = jwt_data['exp']
epoch = math.ceil(time.time())
@@ -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()

View File

@@ -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"""
@@ -155,3 +167,62 @@ class GeoRideOwnerBinarySensorEntity(GeoRideBinarySensorEntity):
""" 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"

View File

@@ -4,10 +4,10 @@
"config_flow": true,
"documentation": "https://github.com/ptimatth/GeorideHA",
"requirements": [
"georideapilib>=0.6.0",
"pyjwt>=1.7.1"
"georideapilib>=0.6.1",
"pyjwt==2.1.0"
],
"dependencies": [],
"codeowners": ["ptimatth"],
"version": "0.6.1"
"version": "0.8.1"
}

View File

@@ -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

View File

@@ -4,5 +4,5 @@
"render_readme": true,
"domains": ["devices_tracker", "sensor"],
"country": ["FR"],
"homeassistant": "2021.4.0"
"homeassistant": "2021.10.0"
}