From 3b3c081703cba08ffd9bedb41f79971600eba5ed Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 17 Feb 2026 16:41:02 +0100 Subject: [PATCH] Use shorthand attributes in sigfox (#163286) --- homeassistant/components/sigfox/sensor.py | 26 +++++------------------ 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/sigfox/sensor.py b/homeassistant/components/sigfox/sensor.py index aece5675cbc..667d4a50602 100644 --- a/homeassistant/components/sigfox/sensor.py +++ b/homeassistant/components/sigfox/sensor.py @@ -6,6 +6,7 @@ import datetime from http import HTTPStatus import json import logging +from typing import Any from urllib.parse import urljoin import requests @@ -123,11 +124,9 @@ class SigfoxDevice(SensorEntity): """Initialise the device object.""" self._device_id = device_id self._auth = auth - self._message_data = {} - self._name = f"{name}_{device_id}" - self._state = None + self._attr_name = f"{name}_{device_id}" - def get_last_message(self): + def get_last_message(self) -> dict[str, Any]: """Return the last message from a device.""" device_url = f"devices/{self._device_id}/messages?limit=1" url = urljoin(API_URL, device_url) @@ -148,20 +147,5 @@ class SigfoxDevice(SensorEntity): def update(self) -> None: """Fetch the latest device message.""" - self._message_data = self.get_last_message() - self._state = self._message_data["payload"] - - @property - def name(self): - """Return the HA name of the sensor.""" - return self._name - - @property - def native_value(self): - """Return the payload of the last message.""" - return self._state - - @property - def extra_state_attributes(self): - """Return other details about the last message.""" - return self._message_data + self._attr_extra_state_attributes = self.get_last_message() + self._attr_native_value = self._attr_extra_state_attributes["payload"]