Skip to content

Commit

Permalink
2023.3.0 #41, #44, #45
Browse files Browse the repository at this point in the history
- Fixed text sensors shown as numeric
- Entity id for new integrations show the clientId
- Breaking change to bluetooth_battery, replaced with battery
  • Loading branch information
bkbilly committed Mar 3, 2023
1 parent c084532 commit b881ee6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
8 changes: 4 additions & 4 deletions lnxlink/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ def setup_discovery_monitoring(self, addon, service, discovery_template):
state_topic = f"{self.pref_topic}/{self.config['mqtt']['statsPrefix']}/{subtopic}"

discovery = discovery_template.copy()
discovery['name'] = addon.name.lower().replace(' ', '_')
discovery['name'] = f"{self.config['mqtt']['clientId']} {addon.name.lower().replace(' ', '_')}"
discovery['unique_id'] = f"{self.config['mqtt']['clientId']}_{service}"
discovery['state_topic'] = state_topic
if addon.getInfo.__annotations__.get('return') == dict:
discovery['json_attributes_topic'] = state_topic
if hasattr(addon, 'icon'):
discovery['icon'] = addon.icon
if hasattr(addon, 'unit'):
discovery['unit_of_measurement'] = addon.unit
if addon.unit == 'json':
discovery['unit_of_measurement'] = ""
discovery['value_template'] = "{{ value_json.status }}"
discovery['json_attributes_template'] = "{{ value_json | tojson }}"
else:
discovery['unit_of_measurement'] = addon.unit
if hasattr(addon, 'title'):
discovery['title'] = addon.title
if hasattr(addon, 'entity_picture'):
Expand All @@ -185,7 +185,7 @@ def setup_discovery_control(self, addon, service, control_name, options, discove
subtopic = addon.name.lower().replace(' ', '/')
state_topic = f"{self.pref_topic}/{self.config['mqtt']['statsPrefix']}/{subtopic}"
discovery = discovery_template.copy()
discovery['name'] = control_name.lower().replace(' ', '_')
discovery['name'] = f"{self.config['mqtt']['clientId']} {control_name.lower().replace(' ', '_')}"
discovery['unique_id'] = f"{self.config['mqtt']['clientId']}_{control_name}"
discovery['enabled_by_default'] = options.get('enabled', True)
discovery["command_topic"] = f"{self.pref_topic}/commands/{service}/{control_name}/"
Expand Down
2 changes: 1 addition & 1 deletion lnxlink/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
update_interval: 5
modules:
- bash
- bluetooth_battery
- battery
- camera_used
- cpu
- disk_usage
Expand Down
32 changes: 32 additions & 0 deletions lnxlink/modules/battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import subprocess
import jc


class Addon():
def __init__(self, lnxlink):
self.name = 'Battery'
self.sensor_type = 'sensor'
self.icon = 'mdi:battery'
self.device_class = 'battery'
self.unit = 'json'

def getInfo(self) -> dict:
stdout = subprocess.run(
'upower --dump',
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).stdout.decode("UTF-8")
upower_json = jc.parse('upower', stdout)

devices = {'status': None}
for device in upower_json:
if 'detail' in device:
if 'percentage' in device['detail']:
name = ''.join([
device.get('vendor', ''),
device.get('model', ''),
]).strip()
devices[name] = device['detail']['percentage']
if devices['status'] is None:
devices['status'] = device['detail']['percentage']
return devices
26 changes: 0 additions & 26 deletions lnxlink/modules/bluetooth_battery.py

This file was deleted.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "lnxlink"
version = "2023.2.0"
version = "2023.3.0"
description = "Internet Of Things (IOT) integration with Linux using MQTT"
readme = "README.md"
keywords = ["lnxlink"]
Expand All @@ -28,6 +28,7 @@ dependencies = [
"pgi>=0.0.11.2",
"pyOpenSSL>=22.1.0",
"requests>=2.28.1",
"jc>=1.23.0"
]


Expand Down

0 comments on commit b881ee6

Please sign in to comment.