GladysProject/Gladys

View on GitHub
front/src/routes/integration/all/tasmota/discover-mqtt/index.js

Summary

Maintainability
C
7 hrs
Test Coverage
import { Component } from 'preact';
import { connect } from 'unistore/preact';
import actions from '../actions';
import TasmotaPage from '../TasmotaPage';
import DiscoverTab from './DiscoverTab';
import { WEBSOCKET_MESSAGE_TYPES } from '../../../../../../../server/utils/constants';

class TasmotaIntegration extends Component {
  async componentWillMount() {
    this.props.getDiscoveredTasmotaDevices('mqtt');
    this.props.getHouses();
    this.props.getIntegrationByName('tasmota');

    this.props.session.dispatcher.addListener(
      WEBSOCKET_MESSAGE_TYPES.TASMOTA.NEW_MQTT_DEVICE,
      this.props.addDiscoveredDevice
    );
  }

  componentWillUnmount() {
    this.props.session.dispatcher.removeListener(
      WEBSOCKET_MESSAGE_TYPES.TASMOTA.NEW_MQTT_DEVICE,
      this.props.addDiscoveredDevice
    );
  }

  render(props) {
    return (
      <TasmotaPage user={props.user}>
        <DiscoverTab {...props} />
      </TasmotaPage>
    );
  }
}

export default connect(
  'user,session,httpClient,housesWithRooms,discoveredDevices,loading,errorLoading',
  actions
)(TasmotaIntegration);