Merge pull request #6506 from happyleavesaoc/enhance-moon
more moon states
This commit is contained in:
commit
4e63e8328e
2 changed files with 17 additions and 9 deletions
|
@ -53,14 +53,22 @@ class MoonSensor(Entity):
|
|||
@property
|
||||
def state(self):
|
||||
"""Return the state of the device."""
|
||||
if self._state >= 21:
|
||||
return 'Last quarter'
|
||||
elif self._state >= 14:
|
||||
return 'Full moon'
|
||||
elif self._state >= 7:
|
||||
return 'First quarter'
|
||||
else:
|
||||
if self._state == 0:
|
||||
return 'New moon'
|
||||
elif self._state < 7:
|
||||
return 'Waxing crescent'
|
||||
elif self._state == 7:
|
||||
return 'First quarter'
|
||||
elif self._state < 14:
|
||||
return 'Waxing gibbous'
|
||||
elif self._state == 14:
|
||||
return 'Full moon'
|
||||
elif self._state < 21:
|
||||
return 'Waning gibbous'
|
||||
elif self._state == 21:
|
||||
return 'Last quarter'
|
||||
else:
|
||||
return 'Waning crescent'
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
|
|
@ -37,7 +37,7 @@ class TestMoonSensor(unittest.TestCase):
|
|||
assert setup_component(self.hass, 'sensor', config)
|
||||
|
||||
state = self.hass.states.get('sensor.moon_day1')
|
||||
self.assertEqual(state.state, 'New moon')
|
||||
self.assertEqual(state.state, 'Waxing crescent')
|
||||
|
||||
@patch('homeassistant.components.sensor.moon.dt_util.utcnow',
|
||||
return_value=DAY2)
|
||||
|
@ -53,4 +53,4 @@ class TestMoonSensor(unittest.TestCase):
|
|||
assert setup_component(self.hass, 'sensor', config)
|
||||
|
||||
state = self.hass.states.get('sensor.moon_day2')
|
||||
self.assertEqual(state.state, 'Full moon')
|
||||
self.assertEqual(state.state, 'Waning gibbous')
|
||||
|
|
Loading…
Add table
Reference in a new issue