Skip to content

Commit

Permalink
Fix bug in time entity
Browse files Browse the repository at this point in the history
  • Loading branch information
ekutner committed Feb 24, 2024
1 parent e582dff commit 98abce2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/home_connect_alt/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"requirements": ["home-connect-async==0.8.0"],
"loggers": ["home_connect_alt", "home_connect_async"],
"ssdp": [],
"version": "1.1.2",
"version": "1.1.3",
"zeroconf": []
}
7 changes: 5 additions & 2 deletions custom_components/home_connect_alt/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def native_value(self) -> time:


def adjust_time(self, t:time, set_option:bool) -> time|None:
""" Adjust the time state when required """

now = datetime.datetime.now()
endtime = datetime.datetime(year=now.year, month=now.month, day=now.day, hour=t.hour, minute=t.minute)
Expand Down Expand Up @@ -133,13 +134,14 @@ def adjust_time(self, t:time, set_option:bool) -> time|None:
return time(hour=endtime.hour, minute=endtime.minute)

def init_time(self) -> time:
""" Initialize the time state """
inittime = datetime.datetime.now() + timedelta(minutes=1)
t = time(hour=inittime.hour, minute=inittime.minute)
return self.adjust_time(t, False)

@classmethod
def get_program_run_time(cls, appliance:Appliance) -> int|None:

""" Try to get the expected run time of the selected program or the remaining time of the running program """
time_option_keys = [
"BSH.Common.Option.RemainingProgramTime",
"BSH.Common.Option.FinishInRelative",
Expand All @@ -149,12 +151,13 @@ def get_program_run_time(cls, appliance:Appliance) -> int|None:
for key in time_option_keys:
o = appliance.get_applied_program_option(key)
if o:
return o
return o.value

return None

@classmethod
def has_program_run_time(cls, appliance:Appliance) ->bool:
""" Check if it's possible to get a program run time estimate """
return cls.get_program_run_time(appliance) is not None


Expand Down

0 comments on commit 98abce2

Please sign in to comment.