def media_position(self) -> Optional[int]: """Position of current playing media in seconds.""" state_var = self._state_variable("AVT", "RelativeTimePosition") if (state_var is None or state_var.value is None or state_var.value == "NOT_IMPLEMENTED"): return None time = str_to_time(state_var.value) if time is None: return None return time.seconds
def media_position(self) -> Optional[int]: """Position of current playing media in seconds.""" state_var = self._state_variable('AVT', 'RelativeTimePosition') if state_var is None or \ state_var.value is None or \ state_var.value == 'NOT_IMPLEMENTED': return None time = str_to_time(state_var.value) if time is None: return None return time.seconds
def test_str_to_time(): assert str_to_time('0:0:10') == timedelta(hours=0, minutes=0, seconds=10) assert str_to_time('0:10:0') == timedelta(hours=0, minutes=10, seconds=0) assert str_to_time('10:0:0') == timedelta(hours=10, minutes=0, seconds=0) assert str_to_time('0:0:10.10') == timedelta(hours=0, minutes=0, seconds=10, milliseconds=10) assert str_to_time('+0:0:10') == timedelta(hours=0, minutes=0, seconds=10) assert str_to_time('-0:0:10') == timedelta(hours=0, minutes=0, seconds=-10) assert str_to_time('') is None assert str_to_time(' ') is None
def test_str_to_time(): """Test string to time parsing.""" assert str_to_time("0:0:10") == timedelta(hours=0, minutes=0, seconds=10) assert str_to_time("0:10:0") == timedelta(hours=0, minutes=10, seconds=0) assert str_to_time("10:0:0") == timedelta(hours=10, minutes=0, seconds=0) assert str_to_time("0:0:10.10") == timedelta(hours=0, minutes=0, seconds=10, milliseconds=10) assert str_to_time("+0:0:10") == timedelta(hours=0, minutes=0, seconds=10) assert str_to_time("-0:0:10") == timedelta(hours=0, minutes=0, seconds=-10) assert str_to_time("") is None assert str_to_time(" ") is None