Skip to content

Commit

Permalink
Move to its own entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Snuffy2 committed Nov 24, 2023
1 parent 4b84c9d commit 726675d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions juicepassproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, device_name, mqtt_settings, juicebox_id=None):
"temperature": None,
"voltage": None,
"power": None,
"debug_message": None,
}
self._init_devices()

Expand All @@ -71,16 +72,34 @@ def _init_devices(self):
self._init_device_temperature(device_info)
self._init_device_voltage(device_info)
self._init_device_power(device_info)
self._init_debug_message(device_info)

def _init_device_status(self, device_info):
name = "Status"
sensor_info = SensorInfo(
name=name, unique_id=f"{self.juicebox_id} {name}", device=device_info
name=name,
unique_id=f"{self.juicebox_id} {name}",
icon="mdi:ev-station",
device=device_info,
)
settings = Settings(mqtt=self.mqtt_settings, entity=sensor_info)
sensor = Sensor(settings)
self.entities["status"] = sensor

def _init_debug_message(self, device_info):
name = "Last Debug Message"
sensor_info = SensorInfo(
name=name,
unique_id=f"{self.juicebox_id} {name}",
expire_after=60,
enabled_by_default=False,
icon="mdi:bug",
device=device_info,
)
settings = Settings(mqtt=self.mqtt_settings, entity=sensor_info)
sensor = Sensor(settings)
self.entities["debug_message"] = sensor

def _init_device_current(self, device_info):
name = "Current"
sensor_info = SensorInfo(
Expand Down Expand Up @@ -236,7 +255,7 @@ def debug_message_try_parse(self, data):
dbg_msg = (
dbg_data[2].replace("https//", "https://").replace("http//", "http://")
)
message["status"] = f"{dbg_level}: {dbg_msg}"
message["debug_message"] = f"{dbg_level}: {dbg_msg}"
return message

def basic_message_publish(self, message):
Expand Down

0 comments on commit 726675d

Please sign in to comment.