Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions homeassistant/components/iaqualink/sensor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Support for Aqualink temperature sensors."""
import logging
from typing import Optional

from homeassistant.components.sensor import DOMAIN
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.helpers.typing import HomeAssistantType

from . import AqualinkEntity
Expand Down Expand Up @@ -36,18 +35,19 @@ def name(self) -> str:
@property
def unit_of_measurement(self) -> str:
"""Return the measurement unit for the sensor."""
if self.dev.system.temp_unit == "F":
return TEMP_FAHRENHEIT
return TEMP_CELSIUS
if self.dev.name.endswith("_temp"):
if self.dev.system.temp_unit == "F":
return TEMP_FAHRENHEIT
return TEMP_CELSIUS

Comment thread
flz marked this conversation as resolved.
@property
def state(self) -> str:
"""Return the state of the sensor."""
return int(self.dev.state) if self.dev.state != "" else None

@property
def device_class(self) -> Optional[str]:
Comment thread
flz marked this conversation as resolved.
"""Return the class of the sensor."""
if self.dev.name.endswith("_temp"):
return DEVICE_CLASS_TEMPERATURE
return None
if self.dev.state == "":
return None

try:
state = int(self.dev.state)
except ValueError:
state = float(self.dev.state)
return state