more moon states

This commit is contained in:
happyleaves
2017-03-09 16:54:04 -05:00
parent 20fcd1f0e2
commit 7892297240
2 changed files with 17 additions and 9 deletions
+15 -7
View File
@@ -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):
+2 -2
View File
@@ -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')