Skip to content

Commit

Permalink
Merge pull request #244 from Snuffy2/Completely-Clear-(since-xxyy)
Browse files Browse the repository at this point in the history
Completely Clear (since xx:yy)
  • Loading branch information
Snuffy2 authored Nov 10, 2023
2 parents 9b546bc + 715acc5 commit 316e330
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions custom_components/places/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ def __init__(self, hass, config, config_entry, name, unique_id):
)

def disable_recorder(self):

if RECORDER_INSTANCE in self._hass.data:
_LOGGER.info(
f"({self.get_attr(CONF_NAME)}) [disable_recorder] Extended Attributes is True, Disabling Recorder"
Expand Down Expand Up @@ -586,6 +585,9 @@ async def async_update(self):
update_type = "Scan Interval"
await self._hass.async_add_executor_job(self.do_update, update_type)

def clear_since_from_state(self, orig_state):
return re.sub(r" \(since \d\d[:/]\d\d\)", "", orig_state)

def is_float(self, value):
if value is not None:
try:
Expand Down Expand Up @@ -851,7 +853,6 @@ def get_dict_from_url(self, url, name):
return get_dict

def get_map_link(self):

if self.get_attr(CONF_MAP_PROVIDER) == "google":
self.set_attr(
ATTR_MAP_LINK,
Expand Down Expand Up @@ -1517,7 +1518,6 @@ def parse_parens(self, curr_options):
for attr_item in item[
(item.find("(") + 1): item.find(")")
].split(","):

if paren_attr_first:
paren_attr_first = False
if attr_item == "-":
Expand Down Expand Up @@ -2073,7 +2073,8 @@ def do_update(self, reason):
# _LOGGER.debug(f"({self.get_attr(CONF_NAME)}) Previous entity attributes: {self._internal_attr}")
if not self.is_attr_blank(ATTR_NATIVE_VALUE) and self.get_attr(CONF_SHOW_TIME):
self.set_attr(
ATTR_PREVIOUS_STATE, str(self.get_attr(ATTR_NATIVE_VALUE)[:-14])
ATTR_PREVIOUS_STATE,
self.clear_since_from_state(str(self.get_attr(ATTR_NATIVE_VALUE))),
)
else:
self.set_attr(ATTR_PREVIOUS_STATE, self.get_attr(ATTR_NATIVE_VALUE))
Expand Down Expand Up @@ -2163,7 +2164,6 @@ def do_update(self, reason):
ATTR_OSM_DICT, self.get_dict_from_url(osm_url, "OpenStreetMaps")
)
if not self.is_attr_blank(ATTR_OSM_DICT):

self.parse_osm_dict()
self.finalize_last_place_name(prev_last_place_name)

Expand Down Expand Up @@ -2264,7 +2264,6 @@ def do_update(self, reason):
or self.is_attr_blank(ATTR_NATIVE_VALUE)
or self.get_attr(ATTR_INITIAL_UPDATE)
):

if self.get_attr(CONF_EXTENDED_ATTR):
self.get_extended_attr()
self.set_attr(ATTR_SHOW_DATE, False)
Expand All @@ -2273,7 +2272,11 @@ def do_update(self, reason):
if self.get_attr(CONF_SHOW_TIME):
self.set_attr(
ATTR_NATIVE_VALUE,
self.get_attr(ATTR_NATIVE_VALUE)[: 255 - 14]
str(
self.clear_since_from_state(
str(self.get_attr(ATTR_NATIVE_VALUE))
)
)[: 255 - 14]
+ " (since "
+ current_time
+ ")",
Expand Down Expand Up @@ -2376,7 +2379,8 @@ def change_show_time_to_date(self):
)
self.set_attr(
ATTR_NATIVE_VALUE,
f"{self.get_attr(ATTR_NATIVE_VALUE)[: -14]}" + f" (since {mmddstring})",
f"{self.clear_since_from_state(str(self.get_attr(ATTR_NATIVE_VALUE)))}"
+ f" (since {mmddstring})",
)

if not self.is_attr_blank(ATTR_NATIVE_VALUE):
Expand Down

0 comments on commit 316e330

Please sign in to comment.