mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use attrs instead of property for Jewish Calendar (#52333)
* Use attrs instead of property for Jewish Calendar * clean time sensor class * move type and prefix up * revert is_on attribute
This commit is contained in:
parent
63c727ac6c
commit
4a94ed8f5a
@ -29,41 +29,23 @@ class JewishCalendarBinarySensor(BinarySensorEntity):
|
|||||||
|
|
||||||
def __init__(self, data, sensor, sensor_info):
|
def __init__(self, data, sensor, sensor_info):
|
||||||
"""Initialize the binary sensor."""
|
"""Initialize the binary sensor."""
|
||||||
self._location = data["location"]
|
|
||||||
self._type = sensor
|
self._type = sensor
|
||||||
self._name = f"{data['name']} {sensor_info[0]}"
|
self._prefix = data["prefix"]
|
||||||
self._icon = sensor_info[1]
|
self._attr_name = f"{data['name']} {sensor_info[0]}"
|
||||||
|
self._attr_unique_id = f"{self._prefix}_{self._type}"
|
||||||
|
self._attr_icon = sensor_info[1]
|
||||||
|
self._attr_should_poll = False
|
||||||
|
self._location = data["location"]
|
||||||
self._hebrew = data["language"] == "hebrew"
|
self._hebrew = data["language"] == "hebrew"
|
||||||
self._candle_lighting_offset = data["candle_lighting_offset"]
|
self._candle_lighting_offset = data["candle_lighting_offset"]
|
||||||
self._havdalah_offset = data["havdalah_offset"]
|
self._havdalah_offset = data["havdalah_offset"]
|
||||||
self._prefix = data["prefix"]
|
|
||||||
self._update_unsub = None
|
self._update_unsub = None
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the icon of the entity."""
|
|
||||||
return self._icon
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Generate a unique id."""
|
|
||||||
return f"{self._prefix}_{self._type}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the entity."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if sensor is on."""
|
"""Return true if sensor is on."""
|
||||||
return self._get_zmanim().issur_melacha_in_effect
|
return self._get_zmanim().issur_melacha_in_effect
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""No polling needed."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
def _get_zmanim(self):
|
def _get_zmanim(self):
|
||||||
"""Return the Zmanim object for now()."""
|
"""Return the Zmanim object for now()."""
|
||||||
return hdate.Zmanim(
|
return hdate.Zmanim(
|
||||||
|
@ -35,33 +35,19 @@ class JewishCalendarSensor(SensorEntity):
|
|||||||
|
|
||||||
def __init__(self, data, sensor, sensor_info):
|
def __init__(self, data, sensor, sensor_info):
|
||||||
"""Initialize the Jewish calendar sensor."""
|
"""Initialize the Jewish calendar sensor."""
|
||||||
self._location = data["location"]
|
|
||||||
self._type = sensor
|
self._type = sensor
|
||||||
self._name = f"{data['name']} {sensor_info[0]}"
|
self._prefix = data["prefix"]
|
||||||
self._icon = sensor_info[1]
|
self._attr_name = f"{data['name']} {sensor_info[0]}"
|
||||||
|
self._attr_unique_id = f"{self._prefix}_{self._type}"
|
||||||
|
self._attr_icon = sensor_info[1]
|
||||||
|
self._location = data["location"]
|
||||||
self._hebrew = data["language"] == "hebrew"
|
self._hebrew = data["language"] == "hebrew"
|
||||||
self._candle_lighting_offset = data["candle_lighting_offset"]
|
self._candle_lighting_offset = data["candle_lighting_offset"]
|
||||||
self._havdalah_offset = data["havdalah_offset"]
|
self._havdalah_offset = data["havdalah_offset"]
|
||||||
self._diaspora = data["diaspora"]
|
self._diaspora = data["diaspora"]
|
||||||
self._state = None
|
self._state = None
|
||||||
self._prefix = data["prefix"]
|
|
||||||
self._holiday_attrs = {}
|
self._holiday_attrs = {}
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Generate a unique id."""
|
|
||||||
return f"{self._prefix}_{self._type}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Icon to display in the front end."""
|
|
||||||
return self._icon
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
@ -142,16 +128,13 @@ class JewishCalendarSensor(SensorEntity):
|
|||||||
class JewishCalendarTimeSensor(JewishCalendarSensor):
|
class JewishCalendarTimeSensor(JewishCalendarSensor):
|
||||||
"""Implement attrbutes for sensors returning times."""
|
"""Implement attrbutes for sensors returning times."""
|
||||||
|
|
||||||
|
_attr_device_class = DEVICE_CLASS_TIMESTAMP
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return dt_util.as_utc(self._state) if self._state is not None else None
|
return dt_util.as_utc(self._state) if self._state is not None else None
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the class of this sensor."""
|
|
||||||
return DEVICE_CLASS_TIMESTAMP
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user