"""Set up the greeneye_monitor component with the given config. Return True if successful, False otherwise."""
result=awaitasync_setup_component(
hass,
DOMAIN,
config,
)
awaithass.async_block_till_done()
returnresult
defmock_with_listeners()->MagicMock:
"""Create a MagicMock with methods that follow the same pattern for working with listeners in the greeneye_monitor API."""
mock=MagicMock()
add_listeners(mock)
returnmock
defasync_mock_with_listeners()->AsyncMock:
"""Create an AsyncMock with methods that follow the same pattern for working with listeners in the greeneye_monitor API."""
mock=AsyncMock()
add_listeners(mock)
returnmock
defadd_listeners(mock:MagicMock|AsyncMock)->None:
"""Add add_listener and remove_listener methods to the given mock that behave like their counterparts on objects from the greeneye_monitor API, plus a notify_all_listeners method that calls all registered listeners."""
mock.listeners=[]
mock.add_listener=mock.listeners.append
mock.remove_listener=mock.listeners.remove
defnotify_all_listeners(*args):
forlistenerinlist(mock.listeners):
listener(*args)
mock.notify_all_listeners=notify_all_listeners
defmock_pulse_counter()->MagicMock:
"""Create a mock GreenEye Monitor pulse counter."""
pulse_counter=mock_with_listeners()
pulse_counter.pulses=1000
pulse_counter.pulses_per_second=10
returnpulse_counter
defmock_temperature_sensor()->MagicMock:
"""Create a mock GreenEye Monitor temperature sensor."""