diff --git a/homeassistant/components/velbus/__init__.py b/homeassistant/components/velbus/__init__.py index be5ce04051c..a63a533e487 100644 --- a/homeassistant/components/velbus/__init__.py +++ b/homeassistant/components/velbus/__init__.py @@ -169,26 +169,23 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: class VelbusEntity(Entity): """Representation of a Velbus entity.""" + _attr_should_poll: bool = False + def __init__(self, channel: VelbusChannel) -> None: """Initialize a Velbus entity.""" self._channel = channel - - @property - def unique_id(self) -> str: - """Get unique ID.""" - if (serial := self._channel.get_module_serial()) == "": - serial = str(self._channel.get_module_address()) - return f"{serial}-{self._channel.get_channel_number()}" - - @property - def name(self) -> str: - """Return the display name of this entity.""" - return self._channel.get_name() - - @property - def should_poll(self) -> bool: - """Disable polling.""" - return False + self._attr_name = channel.get_name() + self._attr_device_info = DeviceInfo( + identifiers={ + (DOMAIN, str(channel.get_module_address())), + }, + manufacturer="Velleman", + model=channel.get_module_type_name(), + name=channel.get_full_name(), + sw_version=channel.get_module_sw_version(), + ) + serial = channel.get_module_serial() or str(channel.get_module_address()) + self._attr_unique_id = f"{serial}-{channel.get_channel_number()}" async def async_added_to_hass(self) -> None: """Add listener for state changes.""" @@ -196,16 +193,3 @@ class VelbusEntity(Entity): async def _on_update(self) -> None: self.async_write_ha_state() - - @property - def device_info(self) -> DeviceInfo: - """Return the device info.""" - return DeviceInfo( - identifiers={ - (DOMAIN, str(self._channel.get_module_address())), - }, - manufacturer="Velleman", - model=self._channel.get_module_type_name(), - name=self._channel.get_full_name(), - sw_version=self._channel.get_module_sw_version(), - ) diff --git a/homeassistant/components/velbus/light.py b/homeassistant/components/velbus/light.py index ad0b150bf22..bd903c76790 100644 --- a/homeassistant/components/velbus/light.py +++ b/homeassistant/components/velbus/light.py @@ -51,11 +51,6 @@ class VelbusLight(VelbusEntity, LightEntity): _channel: VelbusDimmer _attr_supported_feature = SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION - def __init__(self, channel: VelbusDimmer) -> None: - """Initialize the dimmer.""" - super().__init__(channel) - self._attr_name = self._channel.get_name() - @property def is_on(self) -> bool: """Return true if the light is on.""" diff --git a/homeassistant/components/velbus/sensor.py b/homeassistant/components/velbus/sensor.py index 8534a32080e..34642dd3bf1 100644 --- a/homeassistant/components/velbus/sensor.py +++ b/homeassistant/components/velbus/sensor.py @@ -50,33 +50,32 @@ class VelbusSensor(VelbusEntity, SensorEntity): """Initialize a sensor Velbus entity.""" super().__init__(channel) self._is_counter: bool = counter - - @property - def unique_id(self) -> str: - """Return unique ID for counter sensors.""" - unique_id = super().unique_id + # define the unique id if self._is_counter: - unique_id = f"{unique_id}-counter" - return unique_id - - @property - def name(self) -> str: - """Return the name for the sensor.""" - name = super().name + self._attr_unique_id = f"{self._attr_unique_id}-counter" + # define the name if self._is_counter: - name = f"{name}-counter" - return name - - @property - def device_class(self) -> str | None: - """Return the device class of the sensor.""" + self._attr_name = f"{self._attr_name}-counter" + # define the device class if self._is_counter: - return DEVICE_CLASS_ENERGY - if self._channel.is_counter_channel(): - return DEVICE_CLASS_POWER - if self._channel.is_temperature(): - return DEVICE_CLASS_TEMPERATURE - return None + self._attr_device_class = DEVICE_CLASS_ENERGY + elif channel.is_counter_channel(): + self._attr_device_class = DEVICE_CLASS_POWER + elif channel.is_temperature(): + self._attr_device_class = DEVICE_CLASS_TEMPERATURE + # define the icon + if self._is_counter: + self._attr_icon = "mdi:counter" + # the state class + if self._is_counter: + self._attr_state_class = STATE_CLASS_TOTAL_INCREASING + else: + self._attr_state_class = STATE_CLASS_MEASUREMENT + # unit + if self._is_counter: + self._attr_native_unit_of_measurement = channel.get_counter_unit() + else: + self._attr_native_unit_of_measurement = channel.get_unit() @property def native_value(self) -> float | int | None: @@ -84,24 +83,3 @@ class VelbusSensor(VelbusEntity, SensorEntity): if self._is_counter: return float(self._channel.get_counter_state()) return float(self._channel.get_state()) - - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - if self._is_counter: - return str(self._channel.get_counter_unit()) - return str(self._channel.get_unit()) - - @property - def icon(self) -> str | None: - """Icon to use in the frontend.""" - if self._is_counter: - return "mdi:counter" - return None - - @property - def state_class(self) -> str: - """Return the state class of this device.""" - if self._is_counter: - return STATE_CLASS_TOTAL_INCREASING - return STATE_CLASS_MEASUREMENT