Address DSMR Reader review notes (#29209)

* Fix review issues

* Remove None from get method

* No longer need logging import

* Give definition without name a default name
This commit is contained in:
Wim Haanstra 2019-11-30 16:23:03 +01:00 committed by Martin Hjelmare
parent 8ae0d891e4
commit bde453be47
2 changed files with 6 additions and 15 deletions

View file

@ -1,6 +1,4 @@
"""Support for DSMR Reader through MQTT."""
import logging
from homeassistant.components import mqtt
from homeassistant.core import callback
from homeassistant.helpers.entity import Entity
@ -8,8 +6,6 @@ from homeassistant.util import slugify
from .definitions import DEFINITIONS
_LOGGER = logging.getLogger(__name__)
DOMAIN = "dsmr_reader"
@ -34,15 +30,10 @@ class DSMRSensor(Entity):
self._entity_id = slugify(topic.replace("/", "_"))
self._topic = topic
self._name = self._definition["name"]
self._unit_of_measurement = (
self._definition["unit"] if "unit" in self._definition else ""
)
self._icon = self._definition["icon"] if "icon" in self._definition else None
self._transform = (
self._definition["transform"] if "transform" in self._definition else None
)
self._name = self._definition.get("name", topic.split("/")[-1])
self._unit_of_measurement = self._definition.get("unit")
self._icon = self._definition.get("icon")
self._transform = self._definition.get("transform")
self._state = None
async def async_added_to_hass(self):
@ -59,7 +50,7 @@ class DSMRSensor(Entity):
self.async_schedule_update_ha_state()
return await mqtt.async_subscribe(self.hass, self._topic, message_received, 1)
await mqtt.async_subscribe(self.hass, self._topic, message_received, 1)
@property
def name(self):