def device_relay_desired_state( code: str, ab_registry: "Registry" = Depends(get_registry), ) -> RelayState: with registry_transaction(ab_registry) as registry: return RelayState.from_orm( registry.Iot.State.DesiredRelay.get_device_state(code))
def set_mode( mode: ThermostatMode, ab_registry: "Registry" = Depends(get_registry), ) -> ThermostatMode: with registry_transaction(ab_registry) as registry: registry.System.Parameter.set("mode", mode.mode.value) return mode
def examples( anyblok_registry: "Registry" = Depends(get_registry), ) -> List["ExampleSchema"]: with registry_transaction(anyblok_registry) as registry: return [ ExampleSchema.from_orm(el) for el in registry.Example.query().all() ]
def save_device_relay_state( code: str, state: RelayState, ab_registry: "Registry" = Depends(get_registry), ) -> RelayState: with registry_transaction(ab_registry) as registry: return RelayState.from_orm( set_device_state(registry, code, state, registry.Iot.State.Relay))
def create_example( example: ExampleCreateSchema, anyblok_registry: "Registry" = Depends(get_registry), ) -> "ExampleSchema": """Something useful to tell to API user""" with registry_transaction(anyblok_registry) as registry: return ExampleSchema.from_orm( registry.Example.insert(name=example.name))
def device_fuel_gauge_state( code: str, ab_registry: "Registry" = Depends(get_registry), ) -> FuelGaugeState: """HTTP GET""" with registry_transaction(ab_registry) as registry: return FuelGaugeState.from_orm( registry.Iot.State.FuelGauge.get_device_state(code))
def device_thermometer_state( code: str, ab_registry: "Registry" = Depends(get_registry), ) -> ThermometerState: """HTTP GET""" with registry_transaction(ab_registry) as registry: return ThermometerState.from_orm( registry.Iot.State.Thermometer.get_device_state(code))
def device_relay_state( code: str, ab_registry: "Registry" = Depends(get_registry), ) -> RelayState: """HTTP GET""" with registry_transaction(ab_registry) as registry: return RelayState.from_orm( registry.Iot.State.Relay.get_device_state(code))
def device_weather_station_state( code: str, ab_registry: "Registry" = Depends(get_registry), ) -> WeatherStationState: """HTTP GET""" with registry_transaction(ab_registry) as registry: return WeatherStationState.from_orm( registry.Iot.State.WeatherStation.get_device_state(code))
def save_device_weather_station_state( code: str, state: WeatherStationState, ab_registry: "Registry" = Depends(get_registry), ) -> WeatherStationState: with registry_transaction(ab_registry) as registry: return WeatherStationState.from_orm( set_device_state(registry, code, state, registry.Iot.State.WeatherStation))
def set_thermostat_range( code: str, thermostat_range: ThermostatRange, ab_registry: "Registry" = Depends(get_registry), ) -> ThermostatRange: with registry_transaction(ab_registry) as registry: return ThermostatRange.from_orm( registry.Iot.Thermostat.Range.insert(code=code, **dict(thermostat_range)))
def save_device_fuel_gauge_state( code: str, state: FuelGaugeState, ab_registry: "Registry" = Depends(get_registry), ) -> FuelGaugeState: with registry_transaction(ab_registry) as registry: return FuelGaugeState.from_orm( set_device_state(registry, code, state, registry.Iot.State.FuelGauge))
def save_device_weather_station_aprs_packet( packet: APRSWeatherStationPacket, ab_registry: "Registry" = Depends(get_registry), ) -> WeatherStationState: state: WeatherStationState = packet.parse() with registry_transaction(ab_registry) as registry: return WeatherStationState.from_orm( set_device_state(registry, state.station_code, state, registry.Iot.State.WeatherStation))
def save_device_thermometer_state( code: str, state: ThermometerState, ab_registry: "Registry" = Depends(get_registry), ) -> ThermometerState: with registry_transaction(ab_registry) as registry: return ThermometerState.from_orm( set_device_state(registry, code, state, registry.Iot.State.Thermometer))
async def async_create_example( example: ExampleCreateSchema, anyblok_registry: "Registry" = Depends(get_registry), ) -> "ExampleSchema": """Something useful to tell to API user""" with registry_transaction(anyblok_registry) as registry: db_ex = registry.Example.insert(name=example.name) await asyncio.sleep(0.5) ExampleSchema.from_orm(db_ex) return db_ex
def get_thermostat_range( code: str, ab_registry: "Registry" = Depends(get_registry), ) -> ThermostatRange: with registry_transaction(ab_registry) as registry: range_ = (registry.Iot.Thermostat.Range.query().filter_by( code=code).order_by( registry.Iot.Thermostat.Range.create_date.desc()).first()) if not range_: # We don't want to instert a new state range, just creating # a default instance range_ = registry.Iot.Thermostat.Range( start=time(hour=0, minute=0), end=time(hour=23, minute=59), celsius=D("16"), ) return ThermostatRange.from_orm(range_)
def get_mode( ab_registry: "Registry" = Depends(get_registry), ) -> ThermostatMode: with registry_transaction(ab_registry) as registry: return ThermostatMode(mode=registry.System.Parameter.get( "mode", default=Mode.manual.value))