MySensors: Remove prefix from unique_id and change some private property names

This commit is contained in:
functionpointer
2021-01-28 18:59:01 +01:00
parent ce78881837
commit 05141fc4e2

View File

@@ -49,7 +49,7 @@ class MySensorsDevice:
self.node_id: int = node_id self.node_id: int = node_id
self.child_id: int = child_id self.child_id: int = child_id
self.value_type: int = value_type # value_type as int. string variant can be looked up in gateway consts self.value_type: int = value_type # value_type as int. string variant can be looked up in gateway consts
self.child_type = self._mysensors_childsensor.type self.child_type = self._mysensors_child.type
self._values = {} self._values = {}
self._update_scheduled = False self._update_scheduled = False
self.hass = None self.hass = None
@@ -83,22 +83,22 @@ class MySensorsDevice:
) )
@property @property
def _mysensors_sensor(self) -> Sensor: def _mysensors_node(self) -> Sensor:
return self.gateway.sensors[self.node_id] return self.gateway.sensors[self.node_id]
@property @property
def _mysensors_childsensor(self) -> ChildSensor: def _mysensors_child(self) -> ChildSensor:
return self._mysensors_sensor.children[self.child_id] return self._mysensors_node.children[self.child_id]
@property @property
def sketch_name(self) -> str: def sketch_name(self) -> str:
"""Return the name of the sketch running on the whole node (will be the same for several entities!).""" """Return the name of the sketch running on the whole node (will be the same for several entities!)."""
return self._mysensors_sensor.sketch_name return self._mysensors_node.sketch_name
@property @property
def sketch_version(self) -> str: def sketch_version(self) -> str:
"""Return the version of the sketch running on the whole node (will be the same for several entities!).""" """Return the version of the sketch running on the whole node (will be the same for several entities!)."""
return self._mysensors_sensor.sketch_version return self._mysensors_node.sketch_version
@property @property
def node_name(self) -> str: def node_name(self) -> str:
@@ -108,16 +108,15 @@ class MySensorsDevice:
@property @property
def unique_id(self) -> str: def unique_id(self) -> str:
"""Return a unique ID for use in home assistant.""" """Return a unique ID for use in home assistant."""
return f"mys{self.gateway_id}-{self.node_id}-{self.child_id}-{self.value_type}" return f"{self.gateway_id}-{self.node_id}-{self.child_id}-{self.value_type}"
@property @property
def device_info(self) -> Optional[Dict[str, Any]]: def device_info(self) -> Optional[Dict[str, Any]]:
"""Return a dict that allows home assistant to puzzle all entities belonging to a node together.""" """Return a dict that allows home assistant to puzzle all entities belonging to a node together."""
return { return {
"identifiers": {(DOMAIN, f"mys{self.gateway_id}-{self.node_id}")}, "identifiers": {(DOMAIN, f"{self.gateway_id}-{self.node_id}")},
"name": self.node_name, "name": self.node_name,
"manufacturer": DOMAIN, "manufacturer": DOMAIN,
"model": self.node_name,
"sw_version": self.sketch_version, "sw_version": self.sketch_version,
} }